c# – UWP中的FrameworkPropertyMetadata在哪里?

前端之家收集整理的这篇文章主要介绍了c# – UWP中的FrameworkPropertyMetadata在哪里?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
和/或如何在我的控件上定义一个DependencyProperty来分离AffectsMeasure?

编辑:哦,刚看到这个 – 我是否必须在propertychangedhandler中调用InvalidateMeasure?

解决方法

抱歉.对于UWP AffectsMeasure不受支持.对于Framework 3,它可以工作.对于默认的UWP绑定,我正在使用CodeSnipped功能.通过事件处理,您可以采取透明行动.对于我的模型,我的UWP codeSnippet的结果如下所示:
#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

XAML:

<Rectangle Fill="Black" Visibility="{x:Bind IsSelected,Mode=OneWay,Converter={StaticResource BoolToVis}}" />

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

猜你在找的C#相关文章