Reputation: 2874
Using WPF .NET 4.0 in VS2010 RTM: I can't create a fullscreen WPF popup.
If I create a popup that is sized 50% width and 100% height everything works fine, but if I try to create a "full screen" popup sized to 100% width and height it ends up displaying at 100% width and 75% height... the bottom is truncated.
Note: The width and height are actually being expressed in pixels in code, I'm using percent to make the situation a little more understandable...
It "feels" like there is some sort of limit preventing the area of a popup from exceeding ~75% of the total area of the screen.
UPDATE: Here is a Hello World example that shows the problem.
<Window x:Class="TechnologyVisualizer.PopupTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PopupTest"
WindowStyle="None" WindowState="Maximized" Background="DarkGray">
<Canvas x:Name="MainCanvas" Width="1920" Height="1080">
<Popup Placement="Center" VerticalAlignment="Center" HorizontalAlignment="Center" Width="1900" Height="1060" Name="popContent">
<TextBlock Background="Red">Hello World</TextBlock>
</Popup>
<Button Canvas.Left="50" Canvas.Top="50" Content="Menu" Height="60" Name="button1" Width="80"
FontSize="22" Foreground="White" Background="Black" Click="button1_Click" />
</Canvas>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace TechnologyVisualizer
{
/// <summary>
/// Interaction logic for PopupTest.xaml
/// </summary>
public partial class PopupTest : Window
{
public PopupTest()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
popContent.IsOpen = true;
}
}
}
If you run this the bottom 25% of the popup is missing if you change the width of the popup to 500 then it will go full height
Upvotes: 12
Views: 8534
Reputation: 4677
set the with of dialog from code, in constructor
public PopupTest()
{
InitializeComponent();
this.Width = Window.Current.Bounds.Width;
this.Height = Window.Current.Bounds.Height;
}
Upvotes: 0
Reputation: 15403
Your guess about the size limitation (75% of the screen) is correct. It's documented here:
The relevant note is missing from the .NET 4 docs. I think you'll need to use another method of getting full screen. I normally use a maximized, borderless, non-resizable window.
Upvotes: 11
Reputation: 176159
I don't have an installation of VS2010 at hand right now to try it, but if this should turn out to be a bug in WPF (as mentioned in a comment), I'm sure using P/Invoke and this sample posted by Raymond Chen should get it to work:
WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) };
void OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags)
{
DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
if (dwStyle & WS_OVERLAPPEDWINDOW) {
MONITORINFO mi = { sizeof(mi) };
if (GetWindowPlacement(hwnd, &g_wpPrev) &&
GetMonitorInfo(MonitorFromWindow(hwnd,
MONITOR_DEFAULTTOPRIMARY), &mi)) {
SetWindowLong(hwnd, GWL_STYLE,
dwStyle & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(hwnd, HWND_TOP,
mi.rcMonitor.left, mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left,
mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
} else {
SetWindowLong(hwnd, GWL_STYLE,
dwStyle | WS_OVERLAPPEDWINDOW);
SetWindowPlacement(hwnd, &g_wpPrev);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
}
Sorry for not being more helpful right now, but I think the C++ sample can easily converted to C# using the corresponding DllImport
s. Check out pinvoke.net for further help on turning this into C#.
Upvotes: 0