epfor
Topic Author
Posts: 13
Joined: 29 Jun 2024, 22:47

Enum Dependency Property

29 Jun 2024, 22:57

hi and thanks inAdvance:

i created a user control with some dependency properties.
in the end i want this line to work:
        <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]
i use this enum:
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)));

		}
also declared and defined in hpp and cpp as static.
this is the relevent part in my user control xaml:
     <Image Source="{Binding LowerButtonTypeProperty, Converter={StaticResource ImageConverter}, RelativeSource={RelativeSource AncestorType=UserControl}}">
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:
        <local:SettingsUserControl Name="SettingModule" Background="White" Grid.Row="1" Grid.Column="0" Margin="10"
                                     HorizontalAlignment="Stretch" VerticalAlignment="Stretch" LowerButtonTypeProperty="PowerButton">
i try to find what i do wrong.
i am pretty new in noesis so maybe some funny mistake.

thanks again
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Enum Dependency Property

02 Jul 2024, 07:40

Hi, it seems you haven't registered the converter for the enum.
RegisterComponent<EnumConverter<XXX::LowerButtonType>>();
Could you try that?
 
epfor
Topic Author
Posts: 13
Joined: 29 Jun 2024, 22:47

Re: Enum Dependency Property

03 Jul 2024, 22:44

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.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Enum Dependency Property

04 Jul 2024, 13:22

I forgot to mention that you should assign the enum property using just the string value, or the enum value with x:Static:
<local:SettingsUserControl LowerButtonTypeProperty="PowerButton">
<local:SettingsUserControl LowerButtonTypeProperty="{x:Static local:LowerButtonType.PowerButton}">
 
epfor
Topic Author
Posts: 13
Joined: 29 Jun 2024, 22:47

Re: Enum Dependency Property

04 Jul 2024, 13:42

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?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Enum Dependency Property

04 Jul 2024, 13:54

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:
<local:SettingsUserControl LowerButtonTypeProperty="PowerButton">
 
epfor
Topic Author
Posts: 13
Joined: 29 Jun 2024, 22:47

Re: Enum Dependency Property

04 Jul 2024, 17:50

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.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Enum Dependency Property

04 Jul 2024, 19:19

You'll need to include the EnumConverter header:
#include <NsCore/EnumConverter.h>
and maybe use the Noesis namespace if you don't define the corresponding using namespace:
Noesis::RegisterComponent<Noesis::EnumConverter<BasicAssistantScreen::LowerButtonType>>();
 
epfor
Topic Author
Posts: 13
Joined: 29 Jun 2024, 22:47

Re: Enum Dependency Property

05 Jul 2024, 10:06

Worked!

thank you!

Who is online

Users browsing this forum: No registered users and 6 guests