• 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

    • Funny enough, the aesthetic is pretty much the only thing I like from Windows 11 so I don't mind a distro that looks like it but the perks of it being Linux underneath. I'm usually a 'start with the base and build it myself' type Linux person but if a distro is close enough to what I'd likely set it to myself, no reason not to start with a good chunk of the work done for me.
    • Ignoring for the moment the bizarre claim that the new Outlook app is more "agile"... "Microsoft also mentions offline and PST (Outlook data/personal storage table) additions that are continuing to improve. The company is right in this regard as it recently confirmed another new offline feature for New Outlook. And PST file support is also here." This was the dealbreaker for me. If true, and if it works sanely, then "New" Outlook becomes viable. Still, gonna wait for the other shoe to drop...
    • Because Win7 was beautiful, much faster and more functional than XP. Win10 (glossing over 8 as many do) was slightly faster in some cases, more functional in some cases, but some people such as myself hated how it looked and decided it wasn't worth the upgrade. Some people liked (or were ok with) the look, and thus it is a good upgrade. Win11 is like 10, but is less functional between key features being removed and constant bugs/crashes either due to updates, or just things that were never patched. It literally has nothing going for it, and I use it every day at work so I'm quite familiar with it.
    • I switched my mom from Chrome to Firefox and she had a serious meltdown. She even managed to figure out how to reinstall Chrome, which really surprised me. What finally got her to switch was Chrome no longer being supported on Win7 and me putting a Chrome skin on FF, and setting it up identically.
    • Feels very much like most other gnome based Linux distros. There is minimal amounts that are influenced by Windows 11, maybe just enough to make people who are switching comfortable enough with the idea. As far as I can tell its mainly just turning the 'taskbar' panel as a 100% sized static panel, rather than the default dynamic sized. Turning it from the Mac OS Dock into the Windows taskbar. The Arc Menu - that I assume you're taking not with from the screenshots, is indeed the Windows 11 style one, but it has lots of other options too, from the more traditional gnome, Windows 7 etc. Still free to install what ever Window Manager you want once you're comfortable enough with Linux though.
  • Recent Achievements

    • Rising Star
      Phillip0web went up a rank
      Rising Star
    • One Month Later
      Epaminombas earned a badge
      One Month Later
    • One Year In
      Bert Fershner earned a badge
      One Year In
    • Reacting Well
      ChrisOdinUK earned a badge
      Reacting Well
    • One Year In
      Steviant earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      548
    2. 2
      ATLien_0
      206
    3. 3
      +FloatingFatMan
      172
    4. 4
      Michael Scrip
      151
    5. 5
      Som
      136
  • Tell a friend

    Love Neowin? Tell a friend!