使用ResizeMode =" NoResize"最大化窗口WPF [英] maximize window with ResizeMode="NoResize" wpf

查看:217
本文介绍了使用ResizeMode =" NoResize"最大化窗口WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下属性的窗口:



I have a window with the following properties:

ShowInTaskbar="False" WindowStyle="None" ResizeMode="NoResize" Topmost="True" AllowsTransparency="True" Background="Transparent"





我希望按下按钮后最大化窗口使用以下行:





and I want to maximize the window after pressing a button with the following line:

this.WindowState = System.Windows.WindowState.Maximized;





在做因此,窗口位于左上方,但没有最大化。



也使用以下行进行测试但不起作用:





in doing so, the window is positioned me in the upper left but it is not maximized.

also tested with the following lines but did not work:

this.Height = SystemParameters.MaximizedPrimaryScreenHeight;
this.Width = SystemParameters.MaximizedPrimaryScreenWidth;
this.Top = 0; this.Left = 0;





任何人都知道如何解决它?



非常感谢。



Anyone know how to solve it?

Thank you very much.

推荐答案

看起来很奇怪。是这样,我会临时修改调整大小模式,他们最大化。您可能还需要处理事件 StateChanged 或覆盖虚拟保护方法 StateChanged ,以确保您具有相同的 ResizeMode 再次更改 WindowState 时,通过为其分配新值,调用,例如 RestoreBounds 或由UI用户提供。请参阅:

http://msdn.microsoft.com/en-us/library/system.windows.window.statechanged%28v=vs.100%29.aspx [ ^ ],

http:// msdn .microsoft.com / zh-cn / library / system.windows.window.onstatechanged%28v = vs.100%29.aspx [ ^ ];

见另外:

http://msdn.microsoft.com/en-us/library/system.windows.window.resizemode%28v=vs.100%29.aspx [ ^ ],

http://msdn.microsoft .com / zh-CN / library / system.windows.window.windowstate%28v = vs.100%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us /library/system.windows.window.restorebounds%28v=vs.100%29.aspx [ ^ ]。



好好运,

-SA
Looks strange. Is so, I would temporary modified resize mode and them maximized. You may also need to handle the event StateChanged or override the virtual protected method StateChanged, to make sure you have the same ResizeMode when you change the WindowState again, either by assigning a new value to it, calling, for example RestoreBounds or by the UI user. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.window.statechanged%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.window.onstatechanged%28v=vs.100%29.aspx[^];
see also:
http://msdn.microsoft.com/en-us/library/system.windows.window.resizemode%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.window.windowstate%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.window.restorebounds%28v=vs.100%29.aspx[^].

Good luck,
—SA


- 晚了然后再没有 -



从你的代码片段我假设您创建了自己的自定义窗口。首先:如果您使用AllowTransparency,您的窗口将无法显示任何旧样式控件(例如:Web浏览器)。不幸的是,如果没有这个,窗口将不会捕捉到屏幕。



把它放在一边,我做的最大化就是



1.添加最大值/将行为恢复到最大/恢复窗口按钮。此行为只是触发最大化/恢复命令。



2.在我的XAML中,整个窗口逻辑位于边框内。像这样...

-better late then never-

From your code fragment I am assuming that you created your own custom window. First of all: if you use AllowsTransparency your window will not be able to display any old style controls (for example: web browser). Unfortunately, without this, the window will not snap to screen.

Putting that aside, what I did to maximize correctly is to

1. Add a maximize/restore behavior to the max/restore window button. This behavior simply triggers maximize/restore command.

2. In my XAML the entire window logic is inside a border. Like this...
<Border x:Name="PART_WindowBorder">
<!-- window def. here -->
</Border>

3。我的最大化/恢复命令看起来像这样。

3. My maximize/restore command looks like this.

public void Execute(object parameter)
{
    var window = parameter as Window;

    if (window != null)
    {
        // Get border part.
        Border border = window.Template.FindName("PART_WindowBorder", window) as Border;

        // Fix border margin with maximizing (WPF bug)...
        if (window.WindowState == WindowState.Maximized)
        {
            border.Margin = new Thickness(0);
            window.WindowState = WindowState.Normal;
        } 
        else
        {
            border.Margin = new Thickness(6);
            window.WindowState = WindowState.Maximized;
        }
    }
}

所以你只需在最大化时将边距增加到6(偏移量为7,边界为1)。在这里,您还可以使用GetSystemMetrics检查正确的窗口版本和读取边距。



问候,

Tomaz

So you simply increase the margin to 6 when maximized (offset is 7, my border is 1). In here, you can also check for correct window version and read margin using GetSystemMetrics.

Regards,
Tomaz


这篇关于使用ResizeMode =&quot; NoResize&quot;最大化窗口WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆