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?
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>