In my WPF UserControl I have this resource, please observe the comments in the Xml sample.
<UserControl.Resources>
<DataTemplate x:Key="AxisXLabelTemplate">
<ContentPresenter Content="{Binding Path=Content}">
<ContentPresenter.LayoutTransform>
<RotateTransform Angle="{Binding XAxisLabelRotation, UpdateSourceTrigger=PropertyChanged}" /> <!-- This does not work -->
<!-- <RotateTransform Angle="-90" /> This works -->
</ContentPresenter.LayoutTransform>
</ContentPresenter>
</DataTemplate>
</UserControl.Resources>
In the code I have a dependency property defined as follows:
class MyChart: INotifyPropertyChanged
{
public static readonly DependencyProperty XAxisLabelRotationProperty =
DependencyProperty.Register("XAxisLabelRotation", typeof(RotateTransform), typeof(BarChart),
new FrameworkPropertyMetadata((RotateTransform)new RotateTransform(-90.0)));
public RotateTransform XAxisLabelRotation
{
get { return (RotateTransform)GetValue(XAxisLabelRotationProperty); }
set { SetValue(XAxisLabelRotationProperty, value); }
}
...
}
The AxisXLabelTemplate DataTemplate is assigned to an element farther below as follows:
<chart:AxisLabel ElementTemplate="{StaticResource AxisXLabelTemplate}"/>
The problem is that when I use the unbound value for Angle and hard-code it to -90, it works beautifully, and when I try with the bound value to XAxisLabelRotation it doesn't.
Can anyone please help?