Change State
Hi, I have a state enum class like this:
I have configured buttons that change this state in xaml files. My question is how can I change this property in C ++ code and notify Noesis that it changes?
The reason I want to do it. In my game there are some events that are not related to the GUI, but according to some events I want to change the view that is controlled by the ViewModel class which is very similar to the Menu3D example.
Code: Select all
enum class State {
Principal,
Start,
Settings
};The reason I want to do it. In my game there are some events that are not related to the GUI, but according to some events I want to change the view that is controlled by the ViewModel class which is very similar to the Menu3D example.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Change State
First you need to register the enum in the reflection and the converter in the factory (so you can use the enum values in xaml):
Then you expose the property in your ViewModel, that should implement INotifyPropertyChanged in order to notify UI when properties are updated (our application framework provides base class NotifyPropertyChangedBase to simplify that):
Is this what you are looking for?
Code: Select all
// Header file
NS_DECLARE_REFLECTION_ENUM(YourNamespace::State)
// Cpp file
NS_IMPLEMENT_REFLECTION_ENUM(YourNamespace::State, "YourNamespace.State")
{
NsVal("Principal", YourNamespace::State::Principal);
NsVal("Start", YourNamespace::State::Start);
NsVal("Settings", YourNamespace::State::Settings);
}
// In you application component registration function
void RegisterComponents()
{
RegisterComponent<EnumConverter<YourNamespace::State>>();
}Code: Select all
class ViewModel: public NoesisApp::NotifyPropertyChangedBase
{
public:
YourNamespace::State GetState() const { return _state; }
void SetState(YourNamespace::State value)
{
if (_state != value)
{
_state = value;
OnPropertyChanged("State");
}
}
private:
YourNamespace::State _state;
NS_IMPLEMENT_INLINE_REFLECTION(ViewModel, NoesisApp::NotifyPropertyChangedBase)
{
NsProp("State", &ViewModel::GetState, &ViewModel::SetState);
}
};Who is online
Users browsing this forum: No registered users and 5 guests