【发布时间】:2016-03-04 23:36:44
【问题描述】:
在我的 WPF UserControl 中我有这个资源,请观察 Xml 示例中的 cmets。
<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 时却没有。
有人可以帮忙吗?
【问题讨论】:
-
您是否查找过任何绑定错误(输出窗口)?
标签: c# wpf xaml data-binding