ElementName does not work with custom dependency property
Code: Select all
public static readonly DependencyProperty ValidStatsProperty = DependencyProperty.Register("ValidStats", typeof(object), typeof(StatView),
new PropertyMetadata(OnValidStatsChanged));
Code: Select all
<local:StatView Stats="{Binding Colonist.Stats}" ValidStats="{Binding ElementName=root, Path=DataContext.StatType}" />
<TextBlock Text="{Binding ElementName=root, Path=DataContext.StatType}" />
Code: Select all
<local:StatView
Stats="{Binding TotalStats}"
ValidStats="{Binding StatType}" />
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: ElementName does not work with custom depedency property.
Is StatView a control or what class is inheriting from?
Re: ElementName does not work with custom depedency property.
StatView is a UserControl.
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: ElementName does not work with custom depedency property.
I was able to reproduce it if I use the same x:Name for the UserControl and for the control containing the template. Could you please report this problem in our bugtracker?
As a workaround for now you can use a different name in the template:
Does that work for you?
As a workaround for now you can use a different name in the template:
Code: Select all
<Grid x:Name="root2" ...>
...
<DataTemplate>
<Grid>
<local:StatView Stats="{Binding Colonist.Stats}" ValidStats="{Binding ElementName=root2, Path=DataContext.StatType}" />
</Grid>
</DataTemplate>
...
</Grid>
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 87 guests