其中';UWP中的FrameworkPropertyMetadata
本文关键字:中的 FrameworkPropertyMetadata UWP 其中 | 更新日期: 2023-09-27 18:21:51
和/或我如何在我的控件上定义一个指定AffectsMeasure
的DependencyProperty
?
编辑:哦,刚刚看到这个-我必须在属性更改器的this
上调用InvalidateMeasure
吗?
对不起。对于UWP事件,不支持Measure。对于Framework 3+,它是有效的。对于默认的UWP绑定,我正在使用CodeSnipped功能。通过事件处理,您可以表现得透明。我的UWP代码段的结果对于我的型号来说是这样的:
#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版