910211 - how can i have ResizeEnd event in Silverlight?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hamidi
    New Member
    • Apr 2012
    • 7

    910211 - how can i have ResizeEnd event in Silverlight?

    hi
    regarding to the solution given by Jeffrey Tan in the following post:

    i've this question that when my application is a Silverlight application what can i do? WndProc is not available to be overridden, is it?
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    I am sure there are many other ways to do it, but the first thing that came to mind when I saw this question, was to use a simple timer that monitors weather the control is resizing, or has finished resizing. Here is the crude example of how you could achieve this:

    Code:
        public partial class UserControl1 : UserControl
        {
            delegate void FinishedResizeHandler(Size finalSize);
            event FinishedResizeHandler FinishedResizing;
            DispatcherTimer ResizeMonitor;
            Size PreviousSize;
    
            public UserControl1()
            {
                InitializeComponent();
                SetupFinishResizing(500);
                FinishedResizing += UserControl1_FinishedResizing;
            }
    
            void UserControl1_FinishedResizing(Size finalSize)
            {
                label1.Content = finalSize.ToString();
            }
    
            void SetupFinishResizing(int delayInMs)
            {
                // Setup a simple timer.
                ResizeMonitor = new DispatcherTimer();
                ResizeMonitor.Interval = TimeSpan.FromMilliseconds(delayInMs);
                ResizeMonitor.Tick += delegate(object sender, EventArgs e)
                {
                    // if the control has stopped resizing.
                    if (RenderSize == PreviousSize)
                    {
                        ResizeMonitor.Stop();
                        if (FinishedResizing != null) FinishedResizing(PreviousSize);
                    }
                };
    
                // Catch the size changed event.
                SizeChanged += delegate(object sender, SizeChangedEventArgs e)
                {
                    ResizeMonitor.Start();
                    PreviousSize = e.NewSize;
                };
            }
        }
    Note that I used a dispatcher timer for threading convenience, and a label within the user control to display the final size. Hope this helps you on the path to finding a solution!

    Aimee Bailey

    Comment

    • RhysW
      New Member
      • Mar 2012
      • 70

      #3
      Edit: Already answered, duplicate question http://bytes.com/topic/c-sharp/answe...esizeend-event

      Comment

      Working...