• 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.
  • Posts

    • I think they needed to simplify their product lines, having such a range of devices is confusing at best, and yes, I think it's also worth dropping those old line names. So I think it's good for them in the long run, and I bet they found that in their research too. Ask a random consumer which of their products would have been the premium one, and unless they knew Dell products intimately, I doubt they would know. Though I think they could have simplified it further.. "Pro Max Plus", what the hell is going on there?!
    • Wrong again. Electric vehicles are more reliable than gasoline vehicles because they have fewer points of failure. On average, they last 50% longer. Its your right to be incorrect and my right to correct you.
    • Hello, I am using a Hitron CODA56 cable modem with Comcast Xfinity's 1200 Mbps service.  No issues noted.  I had looked at the Motorola and Netgear options for a cable modem, but neither was available for purchase at the time I upgraded my cable connection. There are multiple models in the Netgear Nighthawk X10 line-up.  I am guessing you have either the the Netgear Nighthawk X10 AD7000 model (R8900) or the Netgear Nighthawk X10 AD7200 model (R9000) model, is that correct?  Both of these only have one gigabit WAN (internet) ports for connection to the modem, all of the remaining ports for the LAN side of things are gigabit Ethernet ports.  The 10GbE port on the devices is meant for connection to local NAS storage.  I suppose you could connect the desktop computer directly to it, although it would still be limited by the gigabit connection between the cable modem and the Netgear residential gateway broadband router. I would suggest looking for a residential gateway broadband router from a company like Asus, Netgear, TP-Link or maybe even Ubiquiti, depending upon budget, that has 2.5Gbps (or faster) WAN and LAN ports.  That would allow you to make full use of the 1.2Gbps connection from your ISP as well as have some room for future growth, speed-wise. Regards, Aryeh Goretsky      
  • Recent Achievements

    • Week One Done
      Marites earned a badge
      Week One Done
    • One Year In
      runge100 earned a badge
      One Year In
    • One Month Later
      runge100 earned a badge
      One Month Later
    • One Month Later
      jfam earned a badge
      One Month Later
    • First Post
      TheRingmaster earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      575
    2. 2
      ATLien_0
      183
    3. 3
      +FloatingFatMan
      178
    4. 4
      Michael Scrip
      134
    5. 5
      Xenon
      119
  • Tell a friend

    Love Neowin? Tell a friend!