Dear Community,
I'm trying to migrate a WPF application to WinUI 3 but I'm stymied at simply defining a DependencyProperty in my application's main UI window class. Here's what I wrote:
using Microsoft.UI.Xaml;
public sealed partial class MainWindow : Window
{
public static readonly DependencyProperty RootFontSizeProperty = DependencyProperty.Register("RootFontSize",
typeof(double), typeof(MainWindow),
new PropertyMetadata(8.0));
public double RootFontSize
{
get { return (double)GetValue(RootFontSizeProperty); }
set { SetValue(RootFontSizeProperty, value); }
}
}
The problem is, neither MainWindow nor Window contain GetValue() or SetValue().
If I understand the documentation correctly (https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/custom-dependency-properties), MainWindow must be derived from DependencyObject somewhere in its past. According to https://learn.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.dependencyobject?view=winui-3.0, Microsoft.UI.Xaml.Window is, so MainWindow should be, too.
How do I add a custom DependencyProperty to MainWindow?
Thanks for any help.