1. 程式人生 > >win10 UWP 全屏

win10 UWP 全屏

screen panel his line group pin obj state mod

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/

win10 UWP 全屏