[英]Why does AppWindowTitleBar.PreferredHeightOption cause CS0120 in the Windows App SDK?
我目前第一次使用 Winui-3 和 Windows 應用程序 SDK,因為我通常在經典 Win32 C++ 中編寫應用程序。 我的應用程序有一個高標題欄(48 像素),我希望標題按鈕的大小適當。 我已經嘗試使用 Microsoft 文檔中的方法,但這會導致CS0120 : AppWindowTitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
我還沒有在網上找到任何解決這個確切問題的方法。 將其放入 static 方法不起作用。 在試驗過程中,我發現其他自定義項如AppWindowTitleBar.ForegroundColor = Colors.White;
也不行。 我很困惑。
編輯:添加了標題欄的實現
public ShellPage(ShellViewModel viewModel)
{
ViewModel = viewModel;
InitializeComponent();
ViewModel.NavigationService.Frame = NavigationFrame;
ViewModel.NavigationViewService.Initialize(NavigationViewControl);
AppWindowTitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
App.MainWindow.ExtendsContentIntoTitleBar = true;
App.MainWindow.SetTitleBar(AppTitleBar);
App.MainWindow.Activated += MainWindow_Activated;
AppTitleBarText.Text = "AppDisplayName".GetLocalized();
}
AppWindowTitleBar
沒有PreferredHeightOption
。 這就是您獲得CS0120的原因。
嘗試這個。
public ShellPage(ShellViewModel viewModel)
{
ViewModel = viewModel;
InitializeComponent();
ViewModel.NavigationService.Frame = NavigationFrame;
ViewModel.NavigationViewService.Initialize(NavigationViewControl);
//AppWindowTitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
App.MainWindow.ExtendsContentIntoTitleBar = true; // not sure if you need this line.
this.appWindow = GetAppWindowForCurrentWindow();
this.appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
this.appWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
App.MainWindow.SetTitleBar(AppTitleBar);
App.MainWindow.Activated += MainWindow_Activated;
AppTitleBarText.Text = "AppDisplayName".GetLocalized();
}
private AppWindow appWindow;
private AppWindow GetAppWindowForCurrentWindow()
{
IntPtr hWnd = WindowNative.GetWindowHandle(App.MainWindow);
WindowId wndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(wndId);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.