I’ve created a custom Control called EllipsisTextBlock with a DependencyProperty aiming to receive another Control’s property value:
public static readonly DependencyProperty CopyTextBlockWidthProperty =
DependencyProperty.Register("CopyTextBlockWidth", typeof(double), typeof(EllipsisTextBlock),
new PropertyMetadata(0d, null));
In the EllipsisTextBlock’s parent Grid, I’m binding the other Control’s property like this:
<Grid Margin="10,0,0,0" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MaxHeight="84"/>
<RowDefinition Height="Auto" MaxHeight="72"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" MaxHeight="120"/>
</Grid.RowDefinitions>
<TextBlock x:Name="tbxTeste" Text="{Binding Title}" FontSize="28" Visibility="Collapsed" Grid.Row="0"></TextBlock>
<extensions:EllipsisTextBlock Text="{Binding Title}" FontSize="28" TextWrapping="Wrap" CopyTextBlockWidth="{Binding Path=ActualWidth, ElementName=tbxTeste}" Grid.Row="0"></extensions:EllipsisTextBlock>
...
What happens is that EllipsisTextBlock’s CopyTextBlockWidth property’s Set is never called:
public double CopyTextBlockWidth
{
get { return (double)GetValue(CopyTextBlockWidthProperty); }
set { SetValue(CopyTextBlockWidthProperty, value); }
}
By the way, EllipsisTextBlock class have two other DependencyProperties which works.
Any ideas?
Thanks
Although it is misleading using the XAML attribute syntax, SetBinding is called, not SetValue nor the CLR setter when you assign a binding to a property in XAML.