我创建了自定义控件:
public sealed partial class CustomControl : UserControl
{
/// <summary>
/// Sets and gets the IsWide property.
/// Changes to that property's value raise the PropertyChanged event.
/// </summary>
public bool IsWide
{
get { return (bool)GetValue(IsWideProperty); }
set
{
SetValue(IsWideProperty, value);
Debug.WriteLine("IsWide executed");
}
}
public static readonly DependencyProperty IsWideProperty = DependencyProperty.Register(nameof(IsWide), typeof(bool), typeof(CustomControl), new PropertyMetadata(false, OnWide));
private static void OnWide(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
Debug.WriteLine("OnWide executed");
}
/// <summary>
///
/// </summary>
public CustomControl()
{
this.InitializeComponent();
}
}
我在Page
,
<ctr:CustomControl x:Name="FormattingBar" />
我使用VisualStateGroup
添加了Blend
。
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveVisualStateGroup">
<VisualState x:Name="VisualStateWide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource WideMinWidth}" />
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
但是当我尝试使用IsWide
在VisualState
中设置Blend
属性时,
我收到了这个错误:
所以,我手动编写了这个setter,
<VisualState.Setters>
<Setter Target="FormattingBar.IsWide" Value="True" />
</VisualState.Setters>
运行它,我检查调试窗口VisualStateWide
状态确实在我调整应用程序时触发,但IsWide
属性永远不会得到设置。