How to Collapse the Visibility of the View ?

Topics: Prism v4 - WPF 4
Nov 29, 2011 at 9:16 AM

Hi All,

Is there any possibility to collapse the particular view?

Thanks and Regards,

Sakthi

Developer
Nov 29, 2011 at 4:32 PM
Edited Nov 29, 2011 at 4:40 PM

Hi Sakthi,

If your view is a FrameworkElement, you could directly get the view from the Region and set the Visibility property of the view to Collapsed.

For example, if the view was injected in a Region with a name, you could do something similar to this:

IRegion region = regionManager.Regions["MyRegion"];
FrameworkElement view = region.GetView("MyView") as FrameworkElement;
view.Visibility = Visibility.Collapsed;

Also, you could get the view directly from the Views collection of the Region.

Take into account that, depending of the type of Region where the view is hosted, you could also deactivate the view using the Deactivate method of the Region instead of changing the Visibility property of the view.

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Nov 30, 2011 at 3:21 AM

Hi DCherubini,

I have tried both methods TypeCasting with FrameWorkElement and ViewDeactivate method. Both the methods are not giving the proper solution what i am expecting .

First method :

 while (myRegion.Views.Count() > 2)
            {
                TabControl view = myRegion.GetView(RegionNames.MainViewRegion) as TabControl;
                view.Visibility = Visibility.Collapsed;
                ++count;
            }

Second Method :

  while (myRegion.Views.Count() > 2)
            {
                myRegion.Deactivate(RegionNames.MainViewRegion);
              
            }
Please suggest me with valuable solution.
Thanks and Regards,
Sakthi
Developer
Nov 30, 2011 at 1:09 PM
Edited Nov 30, 2011 at 1:10 PM

Hi,

Based on my understanding of your scenario, you could try using (for example) the foreach statement instead of the while statement, as I believe this can be causing an infinite loop, based on my understanding of the code you provided.
An example of this could be like in the following code snippet:

 

foreach (object view in myRegion.Views)
{
TabControl myView = view as TabControl;
myView.Visibility = Visibility.Collapsed;

}

 

I hope you find this helpful

Agustin Adami
http://blogs.southworks.net/aadami


Dec 2, 2011 at 10:07 AM

Hi Aadami,

I also want to know how to activate and deactivate the views. When i fire the particular events like click.

Thanks and Regards,

Sakthi

 

 

Developer
Dec 2, 2011 at 3:28 PM

Hi,

You might find the following resources useful, where similar issues are addressed:

I hope you find this handy

Agustin Adami
http://blogs.southworks.net/aadami