• 0

[WPF] SizeChanged fires only once


Question

Hey gang,

I'm learning WPF, or attempting to learn, and I have a user control that I would like to have an image resize when the control resizes. However the SizeChanged event is only firing when I add the control to the window.

The code is simple enough:

        private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
           MessageBox.Show("Hthis.grdMain.Height.ToString());
        }

What am I doing wrong?

Link to comment
https://www.neowin.net/forum/topic/1014896-wpf-sizechanged-fires-only-once/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Are you sure the control is changing sizes? It's working for me in the test I set up in my current project.

You can test it by adding something to force the control to resize by a pixel or two to trigger the event.

Make sure you're not capturing the event at a higher level than the control and "e.Handled = true"-ing it, and don't forget to set the event's Handled property to true if that's all you want to do when it resizes. That will prevent any other routed event handlers from trying to respond to the message. (This trips up MouseUp/Down/Move if you have another control using the PreviewMouse- events without Handling them properly.)

You could also intercept the LayoutUpdated event instead.

  • 0
  On 27/07/2011 at 20:14, GreyWolf said:

I've been arguing with routed events all morning trying to implement a gesture system... back/next at the window level, page up/down at container level... :p

Kinect gestures? I am working on that as well, or at least I was until I found a couple of people on the Kinect forums that have a decent process and are working out the details

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.