x:Bind 不适用于 ActualWidth 属性(损坏的 RegisterPropertyChangedCallback )

x:Bind doesn't work on ActualWidth property (broken RegisterPropertyChangedCallback )

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

MainPage.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