【发布时间】:2012-09-05 14:10:53
【问题描述】:
在我们的 Metro 应用程序中,我有一个 enum 类型的附加属性。
当直接将元素上的属性设置为 XAML 属性时,该值设置得很好,但是当在样式中使用 Setter 元素时,虽然设置了属性,但它被设置为 null 值(即,e.NewValue在下面的代码中为空)
这是为什么?它引起了问题,显然不能转换为枚举类型。谢谢。
以下是相关代码:
public static readonly DependencyProperty KeyboardScrollRestrictionStyleProperty =
DependencyProperty.RegisterAttached("KeyboardScrollRestrictionStyle", typeof(KeyboardScrollRestrictionStyle), typeof(FlipViewScrollBehaviour),
new PropertyMetadata(KeyboardScrollRestrictionStyle.TextBox, OnKeyboardScrollRestrictionStyleChanged));
static void OnKeyboardScrollRestrictionStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//I check e.NewValue at breakpoint
}
这可行(e.NewValue 是 TextBox):
<TemplatedControls:WatermarkTextBox
Behaviours:FlipViewScrollBehaviour.KeyboardScrollRestrictionStyle="TextBox"
/>
这不是(e.NewValue 为空):
<Style x:Key="TimesheetLineListViewItemTextBox" TargetType="TextBox">
<Setter Property="Behaviours:FlipViewScrollBehaviour.KeyboardScrollRestrictionStyle" Value="TextBox" />
</Style>
【问题讨论】:
标签: c# wpf xaml microsoft-metro dependency-properties