title | author | date | CreateTime | categories |
---|---|---|---|---|
win10 UWP 全屏 |
lindexi |
2018-06-17 17:51:19 +0800 |
2018-2-13 17:23:3 +0800 |
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有很简单的API可以应用全屏,在电脑,我们经常用窗口,手机经常使用全屏。
参见:http://igrali.com/2015/06/21/full-screen-mode-in-windows-10-universal-apps/
VB 全屏
在点击按钮的时候设置 UWP 窗口在原来全屏的时候变为窗口显示,在窗口显示变为全屏
Sub FullScreenButton() Handles Button.Click
Dim isFullScreen = ApplicationView.GetForCurrentView.IsFullScreenMode
If isFullScreen Then
ApplicationView.GetForCurrentView.ExitFullScreenMode()
Else
ApplicationView.GetForCurrentView.TryEnterFullScreenMode()
End If
End Sub
C++ 全屏
<script src="https://gist.github.com/gyakoo/cfef3ca0403d26a082afc8c055240082.js"></script>参见:https://gist.github.com/gyakoo/cfef3ca0403d26a082afc8c055240082