Silverlight:需要在 Application.Current.Host.Content.FullScreenChanged 事件之后

发布于 2024-09-07 16:13:48 字数 223 浏览 2 评论 0原文

问题:

我正在使用 Silverlight Application.Current.Host.Content.FullScreenChanged 事件来检测用户何时在全屏模式之间来回切换。不幸的是,这个事件似乎在屏幕上的任何内容实际调整大小之前触发。

我需要知道全屏更改和全屏更改完成后各种 FrameworkElements 的 ActualWidth/ActualHeight...有什么想法吗?

Problem:

I'm using the Silverlight Application.Current.Host.Content.FullScreenChanged event to detect when a user switches back and forth between fullscreen mode. Unfortunately it seems that this event fires BEFORE anything on the screen is actually resized.

I need to know the ActualWidth/ActualHeight of various FrameworkElements AFTER the change to and from full screen is complete... Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海未深 2024-09-14 16:13:48

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

CS:

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>

You should be able to get the correct size by handling the SizeChanged event of the main application window. If you explicitly need to know if the application is changing from / to full screen mode, perhaps you could set a flag in the FullScreenChanged event handler - e.g. a bool property called IsFullScreenChanging - you could then check this property in the SizeChanged event handler on the main window, do whatever you need to do and reset the flag in anticipation of the next FullScreenChanged event.

cs:

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>
穿透光 2024-09-14 16:13:48

上面史蒂夫的正确回答中演示的简单答案是使用:(

SizeChangedEventArgs.NewSize

作为单独的简洁答案添加,以方便未来的读者......)

The simple answer demonstrated in Steve's correct response above is to use:

SizeChangedEventArgs.NewSize

(Adding as a seperate concise answer for the convenience of future readers...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文