Windows Universal App全屏按钮

Joe*_*300 15 c# win-universal-app windows-10 uwp

Windows应用商店中的某些应用在"标题栏"中的最小化,最大化和关闭按钮之外还有一个全屏按钮.如果全屏处于活动状态,此按钮看起来类似于每个应用程序在标题栏中具有的退出全屏按钮.这是一个系统控制,如果我如何在我的C#Universal App中使用它?

Her*_*rdo 5

您必须使用该Window.SetTitleBar方法来实现所需的行为.因此,您需要完成以下几个步骤:

首先,启用视图以扩展到标题栏.请注意,您只能设置标题栏的左侧部分.的最小化,最大化关闭按钮依然存在:

CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
Run Code Online (Sandbox Code Playgroud)

设置完毕后,使用以下Window.SetTitleBar方法调用方法UIElement:

Window.Current.SetTitleBar(myTitleBar);
Run Code Online (Sandbox Code Playgroud)

在哪里myTitleBar可能看起来像这样:

<Border x:Name="myTitleBar">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <!-- Title -->
        <TextBlock Grid.Column="0"
                   Text="..."/>

        <!-- Custom buttons attached to the right side -->
        <StackPanel Grid.Column="1"
                    Orientation="Horizontal">
            <Button x:Name="FullScreenButton"/>
            <!-- Use U+E740 FullScreen Icon for the button above -->
        </StackPanel>
    </Grid>
</Border
Run Code Online (Sandbox Code Playgroud)

可以在这里找到Marco Minerva的扩展指南(包括一个很好的XAML行为,可以更好地调整这个用例).