Enum Dependency Property
hi and thanks inAdvance:
i created a user control with some dependency properties.
in the end i want this line to work:
i use this enum:
also declared and defined in hpp and cpp as static.
this is the relevent part in my user control xaml:
i tested my converter and i works.
i made other dependency properties bool type and it also work.
the error i get is:
MainWindow.xaml(64,80): Cannot set value for property 'BasicAssistantScreen.SettingsUserControl.LowerButtonTypeProperty', 'local:LowerButtonType.PowerButton' is not a valid value
i tried also this:
i try to find what i do wrong.
i am pretty new in noesis so maybe some funny mistake.
thanks again
i created a user control with some dependency properties.
in the end i want this line to work:
Code: Select all
<local:SettingsUserControl Name="SettingModule" Background="White" Grid.Row="1" Grid.Column="0" Margin="10"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" [u][b]LowerButtonTypeProperty="local:LowerButtonType.PowerButton">[/b][/u]Code: Select all
namespace XXX
{
enum class LowerButtonType {
PowerButton,
BackButton,
NumButtons
};
}
NS_IMPLEMENT_INLINE_REFLECTION_ENUM(XXX::LowerButtonType, "XXX.LowerButtonType")
{
NsVal("PowerButton", XXX::LowerButtonType::PowerButton);
NsVal("BackButton", XXX::LowerButtonType::BackButton);
}
register the property:
NS_IMPLEMENT_INLINE_REFLECTION(SettingsUserControl, UserControl, "XXX.SettingsUserControl")
{
Noesis::UIElementData* data = NsMeta<Noesis::UIElementData>(Noesis::TypeOf<SelfClass>());
data->RegisterProperty<LowerButtonType>(lower_button_type_property, "LowerButtonTypeProperty", Noesis::PropertyMetadata::Create(LowerButtonType(LowerButtonType::BackButton)));
}
this is the relevent part in my user control xaml:
Code: Select all
<Image Source="{Binding LowerButtonTypeProperty, Converter={StaticResource ImageConverter}, RelativeSource={RelativeSource AncestorType=UserControl}}">
i made other dependency properties bool type and it also work.
the error i get is:
MainWindow.xaml(64,80): Cannot set value for property 'BasicAssistantScreen.SettingsUserControl.LowerButtonTypeProperty', 'local:LowerButtonType.PowerButton' is not a valid value
i tried also this:
Code: Select all
<local:SettingsUserControl Name="SettingModule" Background="White" Grid.Row="1" Grid.Column="0" Margin="10"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" LowerButtonTypeProperty="PowerButton">i am pretty new in noesis so maybe some funny mistake.
thanks again
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Enum Dependency Property
Hi, it seems you haven't registered the converter for the enum.
Could you try that?
Code: Select all
RegisterComponent<EnumConverter<XXX::LowerButtonType>>();Re: Enum Dependency Property
hi,
thanks for the answer.
i actually forgot to register and when i registered it solved another problem i had but not this.
someone told me to implement converter from string to LowerButtonType. i will try to do it and update if it works.
if i understood the rational behind was like that on of the conversion (i guess implicit) betwwen True False to boolean, which worked on my boolean properties.
thanks for the answer.
i actually forgot to register and when i registered it solved another problem i had but not this.
someone told me to implement converter from string to LowerButtonType. i will try to do it and update if it works.
if i understood the rational behind was like that on of the conversion (i guess implicit) betwwen True False to boolean, which worked on my boolean properties.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Enum Dependency Property
I forgot to mention that you should assign the enum property using just the string value, or the enum value with x:Static:
Code: Select all
<local:SettingsUserControl LowerButtonTypeProperty="PowerButton">Code: Select all
<local:SettingsUserControl LowerButtonTypeProperty="{x:Static local:LowerButtonType.PowerButton}">Re: Enum Dependency Property
Thank you!!
the x: Static worked for me.
can you please explain what you meant with the string? i do not understand
did you mean that if i write this:
<local:SettingsUserControl LowerButtonTypeProperty="PowerButton">
i need to create another converter from string to LowerButtonTypeProperty as i was told?
the x: Static worked for me.
can you please explain what you meant with the string? i do not understand
did you mean that if i write this:
<local:SettingsUserControl LowerButtonTypeProperty="PowerButton">
i need to create another converter from string to LowerButtonTypeProperty as i was told?
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Enum Dependency Property
No need to write a custom converter, if you registered the EnumConverter<XXX::LowerButtonType>> then you can directly write the enum string value in the xaml, as I posted above:
Code: Select all
<local:SettingsUserControl LowerButtonTypeProperty="PowerButton">Re: Enum Dependency Property
OK,
i misunderstood you on you first answer.
When I do as you offered as you offered:
Noesis::RegisterComponent<EnumConverter<BasicAssistantScreen::LowerButtonType>>();
i got:
Use of undeclared identifier 'EnumConverter'
should i use some include or implement the converter?
i looked in the forum and saw your same suggestion in many answers which worked so i guess i miss something small.
thanks.
i misunderstood you on you first answer.
When I do as you offered as you offered:
Noesis::RegisterComponent<EnumConverter<BasicAssistantScreen::LowerButtonType>>();
i got:
Use of undeclared identifier 'EnumConverter'
should i use some include or implement the converter?
i looked in the forum and saw your same suggestion in many answers which worked so i guess i miss something small.
thanks.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Enum Dependency Property
You'll need to include the EnumConverter header:
and maybe use the Noesis namespace if you don't define the corresponding using namespace:
Code: Select all
#include <NsCore/EnumConverter.h>Code: Select all
Noesis::RegisterComponent<Noesis::EnumConverter<BasicAssistantScreen::LowerButtonType>>();Who is online
Users browsing this forum: No registered users and 6 guests