-
- realesmedia
- Posts: 85
- Joined:
[C++] property update
I want to update two properties, but my version doesn't work. Can you explain the solution?
Code: Select all
<Canvas DataContext="{StaticResource ViewModel_dc_cursor}">
<Canvas.Resources>
<ViewModel_cursor x:Name="ViewModel_dc_cursor"/>
</Canvas.Resources>
<Image Source="..\icons\cursor_arrow.png" Width="16" Height="25"
Canvas.Left="{Binding pos_x, Mode=TwoWay}" Canvas.Top="{Binding pos_y, Mode=TwoWay}"/>
</Canvas>
Code: Select all
class ViewModel_cursor : public Canvas {
public:
ViewModel_cursor();
virtual void update(NsInt x, NsInt y) {
pos_x = x;
pos_y = y;
};
private:
NsInt pos_x, pos_y;
NS_IMPLEMENT_INLINE_REFLECTION(ViewModel_cursor, Canvas) {
NsMeta<TypeId>("ViewModel_cursor");
NsProp("pos_x", &ViewModel_cursor::pos_x);
NsProp("pos_y", &ViewModel_cursor::pos_y);
}
};
Code: Select all
extern "C" NS_DLL_EXPORT void NsRegisterReflection(Noesis::ComponentFactory* factory, NsBool registerComponents) {
NS_REGISTER_COMPONENT(ViewModel_cursor);
}
Re: [C++] property update
I have no experience with the C++ version of Noesis, but I note the following:
Your ViewModel_cursor class derives from Canvas.
In the MVVM pattern, ViewModels should only contain state (data). The idea of a the view-model pattern is that you can use any other UI technology to render it. But Canvas is a UI element, so a "View".
Secondly, your update method is just poking the pos_x and pos_y data-members, so the view cannot possible know that these have changed. For that, you need to fire a property changed event.
To see how to implement such a view-model using Noesis technology, I recommend you read this documentation:
http://noesisengine.com/docs/Gui.Core.D ... orial.html
Your ViewModel_cursor class derives from Canvas.
In the MVVM pattern, ViewModels should only contain state (data). The idea of a the view-model pattern is that you can use any other UI technology to render it. But Canvas is a UI element, so a "View".
Secondly, your update method is just poking the pos_x and pos_y data-members, so the view cannot possible know that these have changed. For that, you need to fire a property changed event.
To see how to implement such a view-model using Noesis technology, I recommend you read this documentation:
http://noesisengine.com/docs/Gui.Core.D ... orial.html
Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
-
- realesmedia
- Posts: 85
- Joined:
Re: [C++] property update
I've got error with macro NSS()
Code: Select all
"__sSymbolpos_x" undeclaired identifier
Code: Select all
class Cursor : public BaseComponent, public INotifyPropertyChanged {
public:
Cursor();
PropertyChangedEventHandler& PropertyChanged() {
return _propertyChanged;
}
void set_x(NsInt x) {
pos_x = x;
_propertyChanged(this, NSS(pos_x));
}
NsInt get_x() {
return pos_x;
}
void set_y(NsInt y) {
pos_y = y;
_propertyChanged(this, NSS(pos_y));
}
NsInt get_y() {
return pos_y;
}
private:
NsInt pos_x, pos_y;
PropertyChangedEventHandler _propertyChanged;
NS_IMPLEMENT_INLINE_REFLECTION(Cursor, BaseComponent) {
NsMeta<TypeId>("Cursor");
NsImpl<INotifyPropertyChanged>();
NsProp("pos_x", &Cursor::get_x, &Cursor::set_x);
NsProp("pos_y", &Cursor::get_y, &Cursor::set_y);
}
};
Re: [C++] property update
Would it be possible to share your project? What version of Noesis are you using?
Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
-
- realesmedia
- Posts: 85
- Joined:
Re: [C++] property update
Version 1.3.0b4Would it be possible to share your project? What version of Noesis are you using?
Open DX Integration sample from sdk and just paste code listed below (class Cursor).
Re: [C++] property update
I had to change two things for your code to compile
(1) I had to declare the symbols in some CPP file
(2) The getters must be const
(1) I had to declare the symbols in some CPP file
Code: Select all
NS_DECLARE_SYMBOL(pos_x);
NS_DECLARE_SYMBOL(pos_y);
Code: Select all
NsInt get_x() const {
return pos_x;
}
NsInt get_y() const {
return pos_y;
}
Peter Verswyvelen,
Strongly Typed Solutions
Strongly Typed Solutions
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: [C++] property update
First of all thanks to Ziriax for your help here
Are you able to make it work with Ziriax suggestions?

Are you able to make it work with Ziriax suggestions?
-
- realesmedia
- Posts: 85
- Joined:
Re: [C++] property update
Sorry for my slowpok mode enabled. Yes, thanks a lot for sharing solution. I'm able to compile code, and later I check solution for the first sample.
Re: [C++] property update
Cool! Thanks for reporting back.
Who is online
Users browsing this forum: Semrush [Bot] and 0 guests