realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

[C++] Change datamodel from outside the class

12 Jan 2017, 09:43

DataModel component registered from NsRegisterComponent. How can I find this component from outside for calling add_item()? For example, from another component registered with same macro.
class DataModel : public BaseComponent {
public:
	DataModel();
	int add_item(const NsString&, NsInt);
private:
	Ptr<ObservableCollection<CheckListBoxItem> > mCheckListBoxItems;

	NS_IMPLEMENT_INLINE_REFLECTION(DataModel, BaseComponent) {
		NsMeta<TypeId>("DataModel");
		NsProp("TheList", &DataModel::mCheckListBoxItems);
	}
};
Last edited by realesmedia on 13 Feb 2017, 11:51, edited 1 time in total.
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: [C++] Change datamodel from outside the class

12 Jan 2017, 10:01

Now I use this way:
int ProjectProperties::add_item(const NsString& t, NsInt v) {
	DataModel* data_model = (DataModel*)this->FindName("dataModel");
	return (data_model->add_item(t, v));
}
Is it correct way? Or I can use some bind etc. or what?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: [C++] Change datamodel from outside the class

12 Jan 2017, 10:05

Data model organization and logic should be independent from the XAML structure. I mean, you must be able to build and connect your application data without a UI. The UI should just be the representation of your data.

For example, if you plan to create an application to manage a book library, you should be able to create and manage the entire book database from code, without a UI.

But if your application is deeply connected with the UI elements, you can get the view model attached to any UI element by calling element->GetDataContext().

Is that what you are asking? Maybe I need a bit more of context to understand the real problem.

Who is online

Users browsing this forum: Google [Bot] and 83 guests