Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window Resize Handle Event

Tags:

c#

.net

wpf

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.

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

xaml for the window:

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

Event handler:

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.

like image 377
user1663203 Avatar asked Jul 28 '26 17:07

user1663203


1 Answers

Converting my comment into an answer:

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

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

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

like image 90
Federico Berasategui Avatar answered Jul 30 '26 07:07

Federico Berasategui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!