x:Bind 在 ActualWidth 属性上不起作用(损坏的 RegisterPropertyChangedCallback)



我正在开发一个UWP应用程序,因为RegisterPropertyChangedCallback无法处理ActualWidth属性。我提交了一份错误报告,但我预计不会很快得到解决。我需要一个变通方法,使我的x:Bind绑定在ActualWidth属性上工作。任何建议都将不胜感激。

主页.xaml.cs

this.RegisterPropertyChangedCallback(Page.ActualWidthProperty, DependencyPropertyChanged_Page_ActualWidth);
}
public void DependencyPropertyChanged_Page_ActualWidth(global::Windows.UI.Xaml.DependencyObject sender, global::Windows.UI.Xaml.DependencyProperty prop) {
// Doesn't get called
}

XAML

<TextBlock x:Name="text" Text="{x:Bind text.ActualWidth, Mode=OneWay}"/> <!-- always shows zero -->

ActualWidth和ActualHeght在UWP中不可绑定(想知道这个决定背后的原因是什么(。WindowsCommunityToolkit对此有一个解决方案(有点笨拙(。检查https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/main/Microsoft.Toolkit.Uwp.UI/Extensions/FrameworkElement/FrameworkElementExtensions.ActualSize.cs

最新更新