-
- realesmedia
- Posts: 85
- Joined:
[C++] Visual update on property changed
Code: Select all
void ViewModel_imports::add_item() {
Noesis::Ptr<Item_model> new_item = *new Item_model(); // Create new item
mListBoxItems->Add(new_item.GetPtr()); // Add item
new_item->SetIsChecked(is_checked); // !!! change value after addition. Check mark is shown
}
Code: Select all
int ViewModel_imports::check_item(NsSize i, bool state) {
mListBoxItems->Get(i)->SetIsChecked(state); // Check mark not updated
return 0;
}
Code: Select all
void CheckItem::SetIsChecked(bool check) {
_propertyChanged(this, NSS(mChecked));
if (mChecked != check) {
mChecked = check;
}
}
class Item_model : public CheckItem {
// ...
}
Re: [C++] Visual update
I'm not sure this is the reason, but you raise the property changed event before your property actually changed.
Try the following code:
Try the following code:
Code: Select all
void CheckItem::SetIsChecked(bool check) {
if (mChecked != check) {
mChecked = check;
_propertyChanged(this, NSS(mChecked));
}
}
class Item_model : public CheckItem {
// ...
}
Last edited by Ziriax on 24 Feb 2017, 13:38, edited 1 time in total.
Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
-
- realesmedia
- Posts: 85
- Joined:
Re: [C++] Visual update
It's not a reason, visual check mark not shown after edit.I'm not sure this is the reason, but you raise the property changed event before your property actually changed.
Try the following code:
...
Re: [C++] Visual update on property changed
Okay, then the Noesis guys need to look into this.
Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
Re: [C++] Visual update on property changed
Oh hang on, I see something else
You pass NSS(mChecked)
But you should pass the name of the property, not the value.
Let me look for a sample
You pass NSS(mChecked)
But you should pass the name of the property, not the value.
Let me look for a sample
Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
-
- realesmedia
- Posts: 85
- Joined:
Re: [C++] Visual update on property changed
One solution is invoke event manually, but I don't think it's a good practice:
Code: Select all
ViewModel_imports::check_item(NsSize i, bool state) {
Item_model* item = mListBoxItems->Get(i);
item->SetIsChecked(state);
mListBoxItems->CollectionChanged().Invoke(this, NotifyCollectionChangedEventArgs(
NotifyCollectionChangedAction::NotifyCollectionChangedAction_Reset,
i, i, item, item));
return 0;
}
I'll try this.pass NSS(mChecked)
But you should pass the name of the property, not the value.
Last edited by realesmedia on 24 Feb 2017, 10:20, edited 1 time in total.
Re: [C++] Visual update on property changed
I might be wrong, I don't know enough about the C++ part.
But did you get your previous post working with the Cursor and pos_x? If you follow the same approach with the checked property, and it still does not work, then I am out of options.
But did you get your previous post working with the Cursor and pos_x? If you follow the same approach with the checked property, and it still does not work, then I am out of options.
Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
-
- realesmedia
- Posts: 85
- Joined:
Re: [C++] Visual update on property changed
Passing name of property ("IsChecked") instead of value ("mChecked") not works.I'll try this.pass NSS(mChecked)
But you should pass the name of the property, not the value.
Re: [C++] Visual update on property changed
Could you provide the full code of your Item_model and base class?
PS: I'm recovering from a serious flu, so my answers might not make sense if I read them again next week
PS: I'm recovering from a serious flu, so my answers might not make sense if I read them again next week

Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
-
- realesmedia
- Posts: 85
- Joined:
Re: [C++] Visual update on property changed
Could you provide the full code of your Item_model and base class?
Code: Select all
class CheckItem : public Item, public INotifyPropertyChanged {
public:
virtual void SetIsChecked(bool) {
if (mChecked != check) {
mChecked = check;
_propertyChanged(this, NSS(IsChecked));
}
}
virtual bool GetIsChecked() const {
return mChecked;
}
PropertyChangedEventHandler& PropertyChanged() {
return _propertyChanged;
}
protected:
NsBool mChecked;
t_callback_func callback;
private:
PropertyChangedEventHandler _propertyChanged;
NS_IMPLEMENT_INLINE_REFLECTION(CheckItem, BaseComponent) {
NsMeta<TypeId>("CheckItem");
NsImpl<INotifyPropertyChanged>();
NsProp("IsChecked", &CheckItem::GetIsChecked, &CheckItem::SetIsChecked);
}
};
Code: Select all
class Item_model : public CheckItem {
private:
NS_IMPLEMENT_INLINE_REFLECTION(Item_model, BaseComponent) {
NsMeta<TypeId>("ListItem");
NsProp("IsChecked", &Item_model::GetIsChecked, &Item_model::SetIsChecked);
}
};
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 21 guests