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

[C++] Visual update on property changed

24 Feb 2017, 08:23

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 {
// ...
}
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: [C++] Visual update

24 Feb 2017, 09:52

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 {
// ...
}
Last edited by Ziriax on 24 Feb 2017, 13:38, edited 1 time in total.
Peter Verswyvelen,
Strongly Typed Solutions
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: [C++] Visual update

24 Feb 2017, 09:55

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.
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: [C++] Visual update on property changed

24 Feb 2017, 10:01

Okay, then the Noesis guys need to look into this.
Peter Verswyvelen,
Strongly Typed Solutions
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: [C++] Visual update on property changed

24 Feb 2017, 10:03

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
Peter Verswyvelen,
Strongly Typed Solutions
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: [C++] Visual update on property changed

24 Feb 2017, 10:15

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.
Last edited by realesmedia on 24 Feb 2017, 10:20, edited 1 time in total.
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: [C++] Visual update on property changed

24 Feb 2017, 10:19

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.
Peter Verswyvelen,
Strongly Typed Solutions
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: [C++] Visual update on property changed

24 Feb 2017, 10:20

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.
 
Ziriax
Posts: 60
Joined: 10 Dec 2015, 17:59
Location: Belgium
Contact:

Re: [C++] Visual update on property changed

24 Feb 2017, 10:40

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 ;-)
Peter Verswyvelen,
Strongly Typed Solutions
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: [C++] Visual update on property changed

24 Feb 2017, 10:50

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.

Who is online

Users browsing this forum: Google [Bot], jayk.techabbot and 37 guests