Home » WPFRSS

Force Refresh WPF Window

Hi all, I am working with a WPF application. My application contains a re-sizable docked window and floating windows containing user controls representing different pages. Now what i want is when the user re-sizes the dock-able window width i need to reset the width of other windows and make them redraw based on the new width. How can i forcefully redraw the windows to re-arrange its controls based on the new width.
 

11 Answers Found

 

Answer 1

One possible solution is to hook to main window's SizeChanged event. Inside event handler you can call InvalidateVisual()

 

 

Answer 2

I have trapped the event in the application  and tried calling InvalidateVisual(), on all windows  but its not working  for me. The window  is not getting re drawn. I have overrided the void OnRender(System.Windows.Media.DrawingContext drawingContext) function and tried with break point in this function. but i dont know why the function is not invoked by the framework even first rendering. Can any one give me an answer.
 

Answer 3

Hi all can any one help me in this bottle neck situation.
 

Answer 4

hi there ,

You have to handle the Layout_Update Event of the window  ,

store the Width of the dock-able window previously and then check when Layout Update Event Fire if it has been changed again set it

 

Regards

 

Answer 5

Hi vinod,

 

not sure if you are already doing this, but using UpdateLayout()  on the items that need to be updated forces them to redraw.  Of course if your controls  need to be able to handle resize events as well.

 

 

cheers

Anton

 

 

Answer 6

Hi Anton i have tried the UpdateLayout function too but still it not working. I am really confused as i am too new to WPF.
 
 

Answer 8

Hi Vinod,

In my test, I explicitly changed the size and the postion of the floating  window, and the target window  and its content elements will be redrawn automatically. No force  refreshing needed. This is the code I used:

publicpartialclass MainWindow : Window
  {
    Window sw1;
    public MainWindow()
    {
      InitializeComponent();
      sw1 = new Window();
      sw1.Show();
    }

    privatevoid Window_SizeChanged(object sender, SizeChangedEventArgs e)
    {
      sw1.Width = this.Width;
      sw1.Height = this.Height;
      sw1.Left = this.Left + this.Width;
      sw1.Top = this.Top + this.Height;
    }
  }

What's your resizing algorism? Would you please provide a snippet of your code that shows the problem? If you kindly elaborate your problem, you will be able to get quicker and better responses.

Thank you and have a nice day!

Best regards,

Min

 

Answer 9

Hi Vinod,

Have you solved your problem?

If you are using DataBiding on Window.Width and Window.Height, please make sure you explicitly specific the Binding Mode to TwoWay. Here it is OneWay by default. And it seems that the OneWay Bindings to Window.Width and Height will break at the time of the window  is re-rendered.

If you still have any doubts or concerns about this issue, please feel free to let me know.

Best regards,

Min

 

Answer 10

Dear Min actually i am not getting the solution for my real problem. I have tried a lot of things which i get from the forum. I think i am not being able to state my issue correct in the forum so that any one can analize and specify a solution. I will make a sample project and will post that here so that you peoples can check it and suggest me a solution. 
 

Answer 11

I got it cleared at last. Post of Thekiller worked out with the combination from others. I was not well in WPF that was the main issue :-). Any way tanx for all.
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter