b:DataTrigger not working with enums
So I've got a b:DataTrigger that's supposed to go off when a bound value that is an enum is a the right case.
I've got a C# implementation, for sanity checking everything.
In Blend, this all works perfectly when I run my Workspace solution.
And here's my enum in c#.
Meanwhile, over in the actual game running in noesis unmanaged, I'm doing the same thing.
And the triggers do not fire.
The triggers think my bound value is an int.
So if I register my enum instance using a pair of get\set accessors that cast to int... and then change my XAML triggers to listen for integers, it works!
Here's the C++ snippets:
Code: Select all
...
<b:Interaction.Triggers>
<b:DataTrigger Binding="{Binding SignInTransitionState}" Value="SignInIntro">
<b:GoToStateAction StateName="SignInIntroState" TargetName="RootGrid" />
</b:DataTrigger>
</b:Interaction.Triggers>
</Page>
In Blend, this all works perfectly when I run my Workspace solution.
And here's my enum in c#.
Code: Select all
namespace Workspace.Enums
{
public enum SignInTransitionStates
{
SignInIntro = 0,
SignInIdle,
SignInOutro,
MainMenuIntro,
MainMenuIdle,
Gameplay,
COUNT
}
}
And the triggers do not fire.
The triggers think my bound value is an int.
So if I register my enum instance using a pair of get\set accessors that cast to int... and then change my XAML triggers to listen for integers, it works!
Code: Select all
...
<b:Interaction.Triggers>
<b:DataTrigger Binding="{Binding SignInTransitionState}" Value="0">
<b:GoToStateAction StateName="SignInIntroState" TargetName="RootGrid" />
</b:DataTrigger>
</b:Interaction.Triggers>
</Page>
Code: Select all
NS_DECLARE_REFLECTION_ENUM(NoesisEnums::SignInTransitionStates)
enum class SignInTransitionStates : int
{
SignInIntro = 0,
SignInIdle,
SignInOutro,
MainMenuIntro,
MainMenuIdle,
Gameplay,
COUNT
};
NS_IMPLEMENT_REFLECTION_ENUM(NoesisEnums::SignInTransitionStates, "Workspace.Enums.SignInTransitionStates")
{
NsVal("SignInIntro", NoesisEnums::SignInTransitionStates::SignInIntro);
NsVal("SignInIdle", NoesisEnums::SignInTransitionStates::SignInIdle);
NsVal("SignInOutro", NoesisEnums::SignInTransitionStates::SignInOutro);
NsVal("MainMenuIntro", NoesisEnums::SignInTransitionStates::MainMenuIntro);
NsVal("MainMenuIdle", NoesisEnums::SignInTransitionStates::MainMenuIdle);
NsVal("Gameplay", NoesisEnums::SignInTransitionStates::Gameplay);
NsVal("COUNT", NoesisEnums::SignInTransitionStates::COUNT);
}
NoesisEnums::SignInTransitionStates m_signInTransitionState = NoesisEnums::SignInTransitionStates::MainMenuIntro;
int paNVMBackground::GetSignInTransitionStateFromInt() const
{
return (int)m_signInTransitionState;
}
void paNVMBackground::SetSignInTransitionStateFromInt(int transitionState)
{
m_signInTransitionState = (NoesisEnums::SignInTransitionStates)transitionState;
OnPropertyChanged(SignInTransitionState_NoesisName);
}
-
sfernandez
Site Admin
- Posts: 3093
- Joined:
Re: b:DataTrigger not working with enums
It is possible that you are not registering the converter for the enum:
You need to do that in order for the XAML parser to understand the string used in Value="SignInIntro".
We are doing this in our Menu3D demo:
https://github.com/Noesis/Tutorials/blo ... in.cpp#L65
https://github.com/Noesis/Tutorials/blo ... .xaml#L581
Could you try that?
Code: Select all
RegisterComponent<EnumConverter<SignInTransitionStates>>();
We are doing this in our Menu3D demo:
https://github.com/Noesis/Tutorials/blo ... in.cpp#L65
https://github.com/Noesis/Tutorials/blo ... .xaml#L581
Could you try that?
Re: b:DataTrigger not working with enums
Thank you, this is the information I needed to figure it out and get it working.
I had a few issues going on:
The enum Types were not being registered.
A component needed to be registered, that contained a noesis::EnumConverter<MyEnum>, so it could figure out how to get a string to be become my enum type.
My enums were manually being declared as derived from Ints, which interfered somehow with the conversion process within the xaml. I just stripped the :
And now that these were straightened out, I could go back to the trigger, and make the value specify the type explicitly instead by using x:type of lazily relying on implicit string conversions. Which means intellisense to be sure I'm locked onto the right enum value.
I appreciate the help! ☺
I had a few issues going on:
The enum Types were not being registered.
A component needed to be registered, that contained a noesis::EnumConverter<MyEnum>, so it could figure out how to get a string to be become my enum type.
My enums were manually being declared as derived from Ints, which interfered somehow with the conversion process within the xaml. I just stripped the :
Code: Select all
: int
Code: Select all
<DataTrigger Binding="{Binding ClothesType}" Value="{x:Static vm:OutfitType.Pants}">
<Setter TargetName="ClothesImage" Property="Source" Value="{StaticResource PantsImageSource}"/>
</DataTrigger>
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests