gpt4 book ai didi

c# - UWP 中的 FrameworkPropertyMetadata 在哪里?

转载 作者:太空狗 更新时间:2023-10-29 20:42:28 25 4
gpt4 key购买 nike

和/或如何在我的控件上定义一个 DependencyProperty 来分隔 AffectsMeasure

编辑:哦,刚看到这个 - 我是否必须在 propertychangedhandler 的 this 上调用 InvalidateMeasure

最佳答案

对不起。对于 UWP AffectsMeasure不支持。对于 Framework 3+ 它有效。对于默认的 UWP 绑定(bind),我正在使用 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# - UWP 中的 FrameworkPropertyMetadata 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33709028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com