- realesmedia
- Posts: 85
- Joined:
[C++] Change datamodel from outside the class
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.
Code: Select all
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
- Posts: 85
- Joined:
Re: [C++] Change datamodel from outside the class
Now I use this way:
Is it correct way? Or I can use some bind etc. or what?
Code: Select all
int ProjectProperties::add_item(const NsString& t, NsInt v) {
DataModel* data_model = (DataModel*)this->FindName("dataModel");
return (data_model->add_item(t, v));
}
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: [C++] Change datamodel from outside the class
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.
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: Ahrefs [Bot] and 53 guests