Page 1 of 2
[C++] Visual update on property changed
Posted: 24 Feb 2017, 08:23
by realesmedia
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
}
If I try to update check value outside this function check mark not updated but value is set.
int ViewModel_imports::check_item(NsSize i, bool state) {
mListBoxItems->Get(i)->SetIsChecked(state); // Check mark not updated
return 0;
}
void CheckItem::SetIsChecked(bool check) {
_propertyChanged(this, NSS(mChecked));
if (mChecked != check) {
mChecked = check;
}
}
class Item_model : public CheckItem {
// ...
}
Re: [C++] Visual update
Posted: 24 Feb 2017, 09:52
by Ziriax
I'm not sure this is the reason, but you raise the property changed event before your property actually changed.
Try the following code:
void CheckItem::SetIsChecked(bool check) {
if (mChecked != check) {
mChecked = check;
_propertyChanged(this, NSS(mChecked));
}
}
class Item_model : public CheckItem {
// ...
}
Re: [C++] Visual update
Posted: 24 Feb 2017, 09:55
by realesmedia
I'm not sure this is the reason, but you raise the property changed event before your property actually changed.
Try the following code:
...
It's not a reason, visual check mark not shown after edit.
Re: [C++] Visual update on property changed
Posted: 24 Feb 2017, 10:01
by Ziriax
Okay, then the Noesis guys need to look into this.
Re: [C++] Visual update on property changed
Posted: 24 Feb 2017, 10:03
by Ziriax
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
Re: [C++] Visual update on property changed
Posted: 24 Feb 2017, 10:15
by realesmedia
One solution is invoke event manually, but I don't think it's a good practice:
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;
}
pass NSS(mChecked)
But you should pass the name of the property, not the value.
I'll try this.
Re: [C++] Visual update on property changed
Posted: 24 Feb 2017, 10:19
by Ziriax
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.
Re: [C++] Visual update on property changed
Posted: 24 Feb 2017, 10:20
by realesmedia
pass NSS(mChecked)
But you should pass the name of the property, not the value.
I'll try this.
Passing name of property ("IsChecked") instead of value ("mChecked") not works.
Re: [C++] Visual update on property changed
Posted: 24 Feb 2017, 10:40
by Ziriax
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
Re: [C++] Visual update on property changed
Posted: 24 Feb 2017, 10:50
by realesmedia
Could you provide the full code of your Item_model and base class?
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);
}
};
class Item_model : public CheckItem {
private:
NS_IMPLEMENT_INLINE_REFLECTION(Item_model, BaseComponent) {
NsMeta<TypeId>("ListItem");
NsProp("IsChecked", &Item_model::GetIsChecked, &Item_model::SetIsChecked);
}
};
Item class contains onle content and tag properties, so I omit this lines.