代码之家  ›  专栏  ›  技术社区  ›  Scrappydog

Silverlight:在application.current.host.content.fullscreenchanged事件之后需要

  •  1
  • Scrappydog  · 技术社区  · 15 年前

    问题:

    我正在使用silverlight application.current.host.content.fullscreenchanged事件检测用户在全屏模式之间来回切换的时间。不幸的是,此事件似乎在屏幕上的任何内容实际调整大小之前触发。

    我需要知道在全屏和全屏切换完成后各种框架元素的实际宽度/实际高度…有什么想法吗?

    2 回复  |  直到 15 年前
        1
  •  2
  •   Steve Willcock    15 年前

    您应该能够通过处理主应用程序窗口的sizeChanged事件来获得正确的大小。如果您明确需要知道应用程序是否正在从全屏模式更改为全屏模式,也许您可以在全屏更改事件处理程序中设置一个标志-例如,一个名为IsFullScreenChanging的bool属性-然后您可以在主窗口上的SizeChanged事件处理程序中检查此属性,执行所需的操作,并在预测下一个全屏更改事件。

    反恐精英:

    using System.Diagnostics;
    using System.Windows;
    using System.Windows.Controls;
    
    namespace SilverlightApplication1
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                SizeChanged += MainPageSizeChanged;
            }
    
            private static void MainPageSizeChanged(object sender, SizeChangedEventArgs e)
            {
                Debug.WriteLine("Size is now " + e.NewSize);
            }
    
            private void ToggleFullScreenButtonClick(object sender, RoutedEventArgs e)
            {
                Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;
            }
        }
    }
    

    XAML:

    <UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    
    
        <Grid x:Name="LayoutRoot" Background="White">
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="79,110,0,0" Name="FullScreenButton" VerticalAlignment="Top" Width="75" Click="ToggleFullScreenButtonClick" />
        </Grid>
    </UserControl>
    
        2
  •  0
  •   Scrappydog    15 年前

    Steve在上述正确回答中给出的简单答案是:

    SizeChangedEventArgs.NewSize
    

    (为了方便将来的读者,添加为单独的简明答案…)

    推荐文章