UWP中的FrameworkPropertyMetadata在哪里?

时间:2015-11-14 13:41:20

标签: c# windows-10 uwp

和/或如何在我的控件上定义notice_bar以分隔DependencyProperty

编辑:哦,刚看到这个 - 我是否必须在propertychangedhandler中的AffectsMeasure上致电InvalidateMeasure

1 个答案:

答案 0 :(得分:-1)

对不起。对于UWP AffectsMeasure不受支持。对于Framework 3+,它可以工作。对于默认的UWP绑定,我正在使用CodeSnipped功能。通过事件处理,您可以采取透明行动。对于我的模型,我的UWP codeSnippet的结果如下所示:

window.open

XAML:

    #region IsSelected

    public static readonly DependencyProperty IsSelectedProperty =
        DependencyProperty.Register("IsSelected", typeof(bool), typeof(PositionModel),
            new PropertyMetadata((bool)false,
                new PropertyChangedCallback(OnIsSelectedChanged)));

    public bool IsSelected
    {
        get { return (bool)GetValue(IsSelectedProperty); }
        set { SetValue(IsSelectedProperty, value); }
    }

    private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        PositionModel target = (PositionModel)d;
        bool oldIsSelected = (bool)e.OldValue;
        bool newIsSelected = target.IsSelected;
        target.OnIsSelectedChanged(oldIsSelected, newIsSelected);
    }

    protected virtual void OnIsSelectedChanged(bool oldIsSelected, bool newIsSelected)
    {
       // Do what your need in your property changed event
       // In my case, I just raise the PropertyChanged for PropertyChangedEventHandler
       // RaisePropertyChanged(nameof(IsSelected));
    }
    #endregion

Windows 10,Store,VS 2017, Microsoft.NETCore.UniversalWindowsPlatform版本5.2.3