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

无法创建全屏WPF弹出窗口

  •  9
  • Scrappydog  · 技术社区  · 16 年前

    在VS2010 RTM中使用wpf.net 4.0:我无法创建全屏wpf弹出窗口。

    如果我创建一个大小为50%宽度和100%高度的弹出窗口,一切正常,但如果我尝试创建一个“全屏”弹出窗口,大小为100%宽度和高度,它最终显示在100%宽度和75%高度…底部被截断。

    注意:在代码中,宽度和高度实际上是以像素表示的,我使用百分比使情况更易于理解…

    它“感觉”好像有某种限制,防止弹出窗口的面积超过屏幕总面积的75%。

    更新:这里有一个hello world示例,显示了这个问题。

    <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;
            }
    
        }
    }
    

    如果运行此命令,则弹出窗口的底部25%将丢失。如果将弹出窗口的宽度更改为500,则它将变为全高。

    3 回复  |  直到 16 年前
        1
  •  11
  •   RandomEngy    16 年前

    您对大小限制(屏幕的75%)的猜测是正确的。记录如下:

    http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.placementmode%28VS.85%29.aspx

    .NET 4文档中缺少相关说明。我想你需要使用另一种全屏的方法。我通常使用最大化、无边界、不可调整大小的窗口。

        2
  •  0
  •   Dirk Vollmar    16 年前

    我现在没有安装VS2010来尝试它,但是如果这在WPF中是一个bug(如注释中所述),我肯定使用p/invoke和 this sample 由Raymond Chen发布,应该让它工作:

    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);
      }
    }
    

    很抱歉现在没有更多的帮助,但是我认为C++样本可以使用相应的方法轻松转换成C语言。 DllImport S.退房 pinvoke.net 有关将此转换为C_的进一步帮助。

        3
  •  0
  •   Radu Simionescu    10 年前

    在构造函数中,从代码中设置“with of”对话框

    public PopupTest()
    {
        InitializeComponent();
        this.Width = Window.Current.Bounds.Width;
        this.Height = Window.Current.Bounds.Height;
    }
    
    推荐文章