首页 > 代码库 > win10 UWP 全屏

win10 UWP 全屏

win10 能够全屏软件或窗体。窗体有一般、最小化、最大化。我们有新的API设置我们软件是全屏,是窗体。

我们能够使用ApplicationView让我们软件全屏,取消。
以下是一个简单的样例,推断我们软件是不是全屏,假设是,就不全屏,代码在一个ToggleButton

ApplicationView view = ApplicationView.GetForCurrentView();

bool isInFullScreenMode = view.IsFullScreenMode;

if (isInFullScreenMode)  
{
    view.ExitFullScreenMode();
}
else  
{
    view.TryEnterFullScreenMode();
}

IsFullScreenMode为true。如今应用全屏
ExitFullScreenMode退出全屏
TryEnterFullScreenMode进入全屏,进入全屏成功true
假设窗体改变须要知道,能够注冊Window.Current.SizeChanged

public class IsFullScreenModeTrigger : StateTriggerBase  
{
    public IsFullScreenModeTrigger()
    {
        ApplicationView view = ApplicationView.GetForCurrentView();

        SetActive(view.IsFullScreenMode);

        Window.Current.SizeChanged += CurrentWindow_SizeChanged;
    }

    private void CurrentWindow_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
    {
        ApplicationView view = ApplicationView.GetForCurrentView();

        SetActive(view.IsFullScreenMode);
    }
}
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup>
            <VisualState x:Name="InFullScreen">
                <VisualState.StateTriggers>
                    <local:IsFullScreenModeTrigger />
                </VisualState.StateTriggers>
                <VisualState.Setters>
                    <Setter Target="IsFullScreenText.Text" Value="In full screen mode" />
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <StackPanel HorizontalAlignment="Center">
        <Button Click="Button_Click" 
                Content="Toggle full screen"></Button>
        <TextBlock x:Name="IsFullScreenText" 
                    FontSize="72" 
                    TextWrapping="Wrap" 
                    Text="Not in full screen mode"/>
    </StackPanel>
</Grid>  

在我们应用变为全屏,textblock就会In full screen mode

我们能够设置PreferredLaunchWindowingMode,在我们应用打开

ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;

ApplicationViewWindowingMode能够Auto ,PreferredLaunchViewSize设置窗体和ApplicationView.PreferredLaunchViewSize,假设没有设置ApplicationView.PreferredLaunchViewSize会使用上次关闭窗体, FullScreen

win10有非常easy的API能够应用全屏,在电脑。我们常常常使用窗体,手机常常使用全屏。

http://igrali.com/2015/06/21/full-screen-mode-in-windows-10-universal-apps/

<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

win10 UWP 全屏