无法在Blend中设置ViewState.Setters

时间:2016-06-17 07:26:38

标签: c# xaml uwp blend

我创建了自定义控件:

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>

但是当我尝试使用IsWideVisualState中设置Blend属性时, 我收到了这个错误:

Property Sets Error

所以,我手动编写了这个setter,

<VisualState.Setters>
    <Setter Target="FormattingBar.IsWide" Value="True" />
</VisualState.Setters>

运行它,我检查调试窗口VisualStateWide状态确实在我调整应用程序时触发,但IsWide属性永远不会得到设置。

Debug Window

0 个答案:

没有答案