WPF 页面全屏

发布于 2025-01-12 22:16:20 字数 3971 浏览 4 评论 0原文

我现在正在尝试安静地解决一个问题。我在我的 WPF 应用程序中使用 Pages,代码即将完成,最后我想让应用程序全屏显示。

然而,所有说明和提示均适用于窗口 (WindowState = WindowState.Maximized; WindowStyle = WindowStyle.None;页面不知道这些说明)

我的所有页面都是这样开始的:

<Page
x:Class="WPFWiringCabinet.Views.WiringPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlzex="urn:controlzex"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:WPFWiringCabinet.Properties"    
d:DesignHeight="1000"
d:DesignWidth="1920"   
Style="{DynamicResource MahApps.Styles.Page}"
mc:Ignorable="d">

或者这样

<Page
x:Class="WPFWiringCabinet.Views.SelectionPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:WPFWiringCabinet.Properties"
d:DesignHeight="450"
d:DesignWidth="800"
Style="{DynamicResource MahApps.Styles.Page}"

所以我正在考虑更改 DynamicResources MahApps.Styles.Page ,如下所示:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MahApps.Styles.Page" TargetType="{x:Type Page}">
    <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.ThemeBackground}" />
    <Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.ThemeForeground}" />
    <Setter Property="FontSize" Value="{DynamicResource MahApps.Font.Size.Content}" />
</Style>

但是此文件是只读的。 我认为 WPF 应用程序应该像这样工作:我有一些在其中显示页面的窗口。所以我想我需要更改该窗口的设置,但我找不到。在我的 App.xaml 中,我只拥有以下内容:

<Application
x:Class="WPFWiringCabinet.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DispatcherUnhandledException="OnDispatcherUnhandledException"
Exit="OnExit"
Startup="OnStartup"   
>

我没有使用 WPF 应用程序的丰富经验,我曾经使用表单,但我有点被迫使用 WPF。

所以我的问题是,如何强制页面全屏显示,或者我是否以错误的方式设置了项目?

谢谢

编辑:

在ApplicationHostService中我有这个:

  private async Task HandleActivationAsync()
    {
        if (App.Current.Windows.OfType<IShellWindow>().Count() == 0)
        {
            // Default activation that navigates to the apps default page
            _shellWindow = _serviceProvider.GetService(typeof(IShellWindow)) as IShellWindow;
            _navigationService.Initialize(_shellWindow.GetNavigationFrame());
            _rightPaneService.Initialize(_shellWindow.GetRightPaneFrame(), _shellWindow.GetSplitView());
            _shellWindow.ShowWindow();
            _navigationService.NavigateTo(typeof(SelectionPage));
            await Task.CompletedTask;
        }
    }

我相信它应该用于导航目的并显示窗口。 ShellWindow 的定义如下

<controls:MetroWindow
x:Class="WPFWiringCabinet.Views.ShellWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:properties="clr-namespace:WPFWiringCabinet.Properties"
WindowStyle="None"
WindowState="Maximized"
ShowCloseButton="False"
ShowMinButton="False"
ShowTitleBar="False"
ShowInTaskbar="False"
ShowMaxRestoreButton="False"
Loaded="OnLoaded"
Unloaded="OnUnloaded"
mc:Ignorable="d"
MinWidth="1920"
MinHeight="350"
Style="{StaticResource CustomMetroWindow}"
Title="{x:Static properties:Resources.AppDisplayName}">

但看起来该指令没有完成其工作。

I am trying to solve a problem for a quiet while now. I am using Pages in my WPF application, the code is almost done and finally I would like to make the app fullscreen.

However all the instructions and tips are for window (WindowState = WindowState.Maximized;
WindowStyle = WindowStyle.None; Page does not know these instructions)

All of my pages starts like this:

<Page
x:Class="WPFWiringCabinet.Views.WiringPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controlzex="urn:controlzex"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:WPFWiringCabinet.Properties"    
d:DesignHeight="1000"
d:DesignWidth="1920"   
Style="{DynamicResource MahApps.Styles.Page}"
mc:Ignorable="d">

Or like this

<Page
x:Class="WPFWiringCabinet.Views.SelectionPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:WPFWiringCabinet.Properties"
d:DesignHeight="450"
d:DesignWidth="800"
Style="{DynamicResource MahApps.Styles.Page}"

So I was thinking about changing the DynamicResources MahApps.Styles.Page which is like this:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MahApps.Styles.Page" TargetType="{x:Type Page}">
    <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.ThemeBackground}" />
    <Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.ThemeForeground}" />
    <Setter Property="FontSize" Value="{DynamicResource MahApps.Font.Size.Content}" />
</Style>

However this file is read only.
What I believe the WPF app should work like this: I have some window in which I am showing the pages. So I guess that I need to change the settings of that window, which I can not find. In my App.xaml I hove only following:

<Application
x:Class="WPFWiringCabinet.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DispatcherUnhandledException="OnDispatcherUnhandledException"
Exit="OnExit"
Startup="OnStartup"   
>

I do not have big experiences with WPF apps, I used to work with forms, but I was kinda forced to use the WPF.

So my question is, how can I force the Page to be in fullscreen or did I setup the project wrong way?

Thanks

EDIT:

In ApplicationHostService I have this:

  private async Task HandleActivationAsync()
    {
        if (App.Current.Windows.OfType<IShellWindow>().Count() == 0)
        {
            // Default activation that navigates to the apps default page
            _shellWindow = _serviceProvider.GetService(typeof(IShellWindow)) as IShellWindow;
            _navigationService.Initialize(_shellWindow.GetNavigationFrame());
            _rightPaneService.Initialize(_shellWindow.GetRightPaneFrame(), _shellWindow.GetSplitView());
            _shellWindow.ShowWindow();
            _navigationService.NavigateTo(typeof(SelectionPage));
            await Task.CompletedTask;
        }
    }

Which I believe should work for navigation purposes and also showing the window. And the ShellWindow is define like this

<controls:MetroWindow
x:Class="WPFWiringCabinet.Views.ShellWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:properties="clr-namespace:WPFWiringCabinet.Properties"
WindowStyle="None"
WindowState="Maximized"
ShowCloseButton="False"
ShowMinButton="False"
ShowTitleBar="False"
ShowInTaskbar="False"
ShowMaxRestoreButton="False"
Loaded="OnLoaded"
Unloaded="OnUnloaded"
mc:Ignorable="d"
MinWidth="1920"
MinHeight="350"
Style="{StaticResource CustomMetroWindow}"
Title="{x:Static properties:Resources.AppDisplayName}">

But it looks like the instruction does not do its job.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文