在我的WPF UserControl中我有這個資源,請觀察Xml示例中的註釋。在DataTemplate中的RotateTransform Angle上綁定不起作用
<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>
在我已依賴項屬性定義爲代碼如下:
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); }
}
...
}
的AxisXLabelTemplate DataTemplate中被分配給一個元素更遠下面如下:
<chart:AxisLabel ElementTemplate="{StaticResource AxisXLabelTemplate}"/>
的問題是當我使用Angle的未綁定值並將其硬編碼爲-90時,它的效果非常好,當我嘗試使用XAxisLabelRotation的綁定值時,它不會。
任何人都可以請幫忙嗎?
和你尋找任何綁定錯誤(輸出窗口)? –