Wuceng
Topic Author
Posts: 10
Joined: 04 Aug 2024, 16:43

Data Binding to property with name "Name" does not work.

29 Dec 2024, 18:24

Hey!
I have a small element that uses databindings and found something I can't explain.
If I call my bound property "Name" it doesn't evaluate properly. If I call it anything else but "Name" it does.
Is that some kind of hidden protected property name I shouldn't use?


Here an excerpt of my surrounding code:

.h of my UserControl:
Noesis::String Name = "GameMode Name";

.cpp of my UserControl:
NS_IMPLEMENT_REFLECTION(GameModeSelectionElement)
{
//NsProp("Name", &GameModeSelectionElement::Name); --> THIS DOES NOT WORK!
NsProp("GameModeName", &GameModeSelectionElement::Name); --> THIS WORKS?!
}

XAML:

//<Label HorizontalAlignment="Center" FontSize="36" Content="{Binding Name}"/> --> THIS in combination with the commented "Name" property DOES NOT WORK!
<Label HorizontalAlignment="Center" FontSize="36" Content="{Binding GameModeName}"/> --> THIS in combination with the "GameModeName" property DOES WORK!
 
User avatar
sfernandez
Site Admin
Posts: 3198
Joined: 22 Dec 2011, 19:20

Re: Data Binding to property with name "Name" does not work.

30 Dec 2024, 11:57

Hello,

The "Name" property is already defined by the UserControl's base class FrameworkElement. As indicated in the documentation the dependency property "Name" provides a reference so that code-behind, such as event handler code, can refer to a markup element after it is constructed by the XAML parser.

This property is typically set in XAML by using the x:Name attribute:
<MyUserControl x:Name="MyControl".../>
Control inherited classes should not define a "Name" property, you should use a different name in that case.
 
KeldorKatarn
Posts: 234
Joined: 30 May 2014, 10:26

Re: Data Binding to property with name "Name" does not work.

30 Jan 2025, 14:25

Hey!
I have a small element that uses databindings and found something I can't explain.
If I call my bound property "Name" it doesn't evaluate properly. If I call it anything else but "Name" it does.
Is that some kind of hidden protected property name I shouldn't use?
[...]
Name indeed should be avoided. That's the property that's used for a lot, including Bindings using ElementName as the source.
And not to mention Caliburn uses that for its conventions ;)

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 2 guests