首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么AppWindowTitleBar.PreferredHeightOption会导致Windows中的CS0120?

为什么AppWindowTitleBar.PreferredHeightOption会导致Windows中的CS0120?
EN

Stack Overflow用户
提问于 2022-08-17 23:13:33
回答 1查看 60关注 0票数 0

我目前第一次使用Winui-3和Windows,因为我通常用经典的Win32 C++编写应用程序。我的应用程序有一个高标题栏(48 to ),我希望标题按钮的大小适当。我已经尝试过使用Microsoft文档中的方法,但这会导致CS0120AppWindowTitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;

我还没有在网上找到任何解决这个确切问题的方法。把它应用到静态方法中是行不通的。在实验中,我发现像AppWindowTitleBar.ForegroundColor = Colors.White;这样的其他自定义也不起作用。我很困惑。

编辑:添加标题栏的实现

代码语言:javascript
复制
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();
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-18 01:44:47

AppWindowTitleBar没有PreferredHeightOption。这就是为什么你要得到CS0120

尝尝这个。

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73395825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档