窗口调整大小事件 [英] Window Resize Handle Event

查看:69
本文介绍了窗口调整大小事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中的某些元素具有自定义大小调整事件,所有这些都可以正常工作.但是,它们被一种情况弄得一团糟:

Certain elements of my application have custom resizing events, which all work. However, they are messed up by one case:

将鼠标悬停在窗口的边框上时,光标变为调整大小的句柄,然后单击(但不要拖动),元素的大小将错误调整,并且不会触发我的处理程序.

When hovering over the border of the window, so that the cursor becomes the resize handle, and you click (but do not drag), the elements resize incorrectly, and my handlers are not fired.

我一直在寻找这样的事件,但是找不到任何匹配的事件.我只想为此事件创建一个处理程序,以免调整元素的大小.

I've looked for such an event but cannot find anything that matches. I'd like to simply make a handler for this event to avoid glitchy resizing of my elements.

我正在使用C#/WPF和.NET 4

I'm using C#/WPF, with .NET 4

该窗口的xaml:

<Window x:Class="XHealth.MainWindow"
    Name="mainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DataGridTemplateSample"
    xmlns:XH="clr-namespace:XHealth"
    xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"

    SizeChanged="update_size"
    Title="XHealth"  Loaded="Window_Loaded" WindowState="Normal" WindowStartupLocation="CenterScreen" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  SizeToContent="WidthAndHeight" WindowStyle="ThreeDBorderWindow"  MinWidth="650" MinHeight="648" Width="Auto"  VerticalAlignment="Top" DataContext="{Binding}" PreviewKeyDown="Window_KeyDown">

事件处理程序:

public void update_size(object sender, RoutedEventArgs e )
{
        if (resultsTab.IsSelected){
          Grid.SetRowSpan(dataGrid1, 2);
          Grid.SetRowSpan(dataGrid2, 2);
        }
}

此处理程序按预期方式执行,但是在未拖动调整大小手柄时不会触发,这使我认为单击调整大小手柄是另外一个事件.

This handler performs as intended, but does not trigger when the resize handle is not dragged, which leads me to believe clicking the resize handle is a different event.

而且,这种情况只会发生一次-我的调整大小处理程序生效后,单击调整大小句柄将无效.

Also, this only happens once - once my resize handler takes effect, clicked the resize handle has no effect.

推荐答案

将我的评论转换为答案:

Converting my comment into an answer:

可以通过不在网格中放置任何*来解决.

That could be resolved by not putting any * in the Grid.

此外,如果将窗口设置为 SizeToContent ,则应仅 SizeToContent = Width ,以防止窗口不断缩放.

Also, if the Window is set to SizeToContent, you should only SizeToContent=Width to prevent the window from scaling endlessly.

删除所有事件处理程序,这就是hack.

Remove all the event handlers stuff, that's hack.

这篇关于窗口调整大小事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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