MVVM and the Infragistics DockManager Control – Part Deux

When I last posted about using MVVM and the Infragistics DockManager Control, I was talking about dynamically adding ContentPane controls to the DocumentContentHost.
 
In a typical application, some content is used for navigation. In the case of Visual Studio, this can be represented by the Solution Explorer or Class View, enabling a person to jet off to the spot they are looking for. With this Infragistics XamDockManager control, these types of panes exist within the DockManager.Panes collection, but not within the DocumentContentHost. The one concern with navigation panes is that they are typically content-heavy with respect to either processing power or resource usage. To combat this, you’ll likely want not to destroy these panels each time you close them but, rather, simply hide them; to be made visible again at a later time.
 
Setting the CloseAction property of the ContentPane to "HidePane" (Hide Pain?) partially helps you with this. The problem is that, using MVVM, there’s no way to change the visibility of the pane again to make it visible again. There is, however, a work-around. You can bind the visibility of the ContentPane to a boolean property of your ViewModel, and raise the INotifyPropertyChanged event every time you set the value, rather than trying to (more typically) not raise the value unless the property’s value has changed.
 
In the attached sample, I am combining some features of PRISM (DelegateCommands) with this to simplify the coding that is occuring. Here is some pseudo-code representing the relevant bits:
 
In MainWindowViewModel:
 

public

MainWindowViewModel() {     

     ShowNavigation =

new DelegateCommand<object>(x => NavigationVisible = true);

}
 

public DelegateCommand<object> ShowNavigation { get; set; }

public bool NavigationVisible {

     get { return navigationVisible; }

     set { navigationVisible = value; OnPropertyChanged("NavigationVisible"); }

}

 
In Window1:

<

MenuItem Header="_Control Panel" Command="{Binding ShowNavigation}"/>

<

igDock:ContentPane CloseAction="HidePane" Visibility="{Binding NavigationVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}}">

<!– Content Here –>

</

igDock:ContentPane>

 
You can find the complete sample here:
 
 
Special thanks to Sam of Infragistics for helping me figure out that not declaring Mode=TwoWay makes for a lot of confusion.

 

Advertisements

6 thoughts on “MVVM and the Infragistics DockManager Control – Part Deux

  1. Christ! Why does the mode have to be two way? That doesn’t make sense. I’ve been trying to bind to a bool all day. Thanks for the post.

  2. I was looking for such a solution some time ago and was amazed to find it in your blog now. Well, almost – the sample is not on skydrive anymore. Is there any possibility to get the sample code even if I’m more than two years late?

  3. Can you update source code link?

  4. I inadvertently deleted the previous sample. I rereated it and you can find it here.

    https://skydrive.live.com/redir?resid=9D2E96F2AA6AE85F!1116

  5. Hi, can you update the link again please?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s