ApplicationView.TryEnterFullScreenMode 方法

定义

尝试将应用置于全屏模式。

public:
 virtual bool TryEnterFullScreenMode() = TryEnterFullScreenMode;
bool TryEnterFullScreenMode();
public bool TryEnterFullScreenMode();
function tryEnterFullScreenMode()
Public Function TryEnterFullScreenMode () As Boolean

返回

Boolean

bool

如果应用处于全屏模式,则为 true;否则为 false

示例

此示例演示如何切换全屏模式并设置 PreferredLaunchWindowingMode 属性。

<Button x:Name="ToggleFullScreenModeButton" Content="Toggle full screen" 
        Click="ToggleFullScreenModeButton_Click"/>
private void ToggleFullScreenModeButton_Click(object sender, RoutedEventArgs e)
{
    var view = ApplicationView.GetForCurrentView();
    if (view.IsFullScreenMode)
    {
        view.ExitFullScreenMode();
        ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
        // The SizeChanged event will be raised when the exit from full-screen mode is complete.
    }
    else
    {
        if (view.TryEnterFullScreenMode())
        {
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
            // The SizeChanged event will be raised when the entry to full-screen mode is complete.
        }
    }
}

注解

若要在用户重启应用时保留全屏模式,如果对 TryEnterFullScreenMode 的调用返回 true,请将 PreferredLaunchWindowingMode 设置为 FullScreen。 调用 ExitFullScreenMode 时,应将 PreferredLaunchWindowingMode 设置回 AutoPreferredLaunchViewSize

当视图进入或退出全屏模式时,系统会引发 CoreWindow.SizeChanged 事件。 这作为 Window.SizeChanged 事件向 XAML 应用公开,作为 window.resize 事件公开给 HTML 应用。

适用于

另请参阅