tags:

views:

1028

answers:

3

I have 2 tab items. In tab No.1 I have a control which corresponds to window resize event and need to call PointToScreen().

The problem is Tab no 2 is active and I resize the window, the control in tab no.1 reacts and fail because its' visual is not being rendered and I get "This Visual is not connected to a PresentationSource" exception.

Do you know how to check this case before I call PointoScreen ?

Thanks Ariel

A: 

The way I would perform this is in the code behind, add and remove the event handler based upon the tab being selected. When Tab1 is selected, do an AddHandler on the control for the Window Resize Event and when Tab1 is unselected (i.e. a different tab comes to the front) do a RemoveHandler for the control.

Stephen Wrighton
+2  A: 

You can check "IsVisible" -- This corresponds, not as a shortcut for comparing the visibility property, but also tells you if the thing is being rendered on the screen. I'm not entirely sure how how this plays into virtualization of UIElements, but I think it is correctly aware of those scenarios.

dhopton
A: 

I had the similar issue with getting this exception. I subscribed on SelectedChanged event of tab control which is does not mean that the selection changed in WPF. See http://dotbay.blogspot.com/2009/10/in-wpf-selectionchanged-does-not-mean.html for more details. Hope, this will help you. Alex.

BorodaAlex