One very strong MSDN article on MVVM from Josh Smith contains a sample that dynamically adds tabs to a content section of a tab control. One of the keys to this article is the DataTemplating that ties the ViewModel of the observable collection to the view to be represented, thus allowing the dynamic addition and removal of content in the tab control.
I am looking to perform the same thing, but with the DocumentContentHost of the DockManager, dynamically adding/removing ContentPanes based on the collection of detail ViewModels. Has anyone successfully been able to accomplish something like this?
<StrugglingButPersistent>JH</StrugglingButPersistent>
I have resolved the issue. The result (and sample code) can be found here.
Using VS2010 with version v11.2 of the dock manager new tabs don't get focus. When opened they are behind existing tabs. Any idea why this is happening?
You need to set the tab to "active".
I had to do the following:
in the xaml:
<igDock:XamDockManager x:Name="xamDockManager" Theme="[Current]" ActivePaneChanged="OnActivePaneChanged">
in the code behind:
public static DependencyProperty ActivePaneChangedProperty = DependencyProperty.Register("TimActivePaneChanged", typeof(ICommand), typeof(MyWindow), new PropertyMetadata(null));
IMyTabbedControl currentTab;
public ICommand ActivePaneChanged { get { return (ICommand)GetValue(ActivePaneChangedProperty); } set { SetValue(ActivePaneChangedProperty, value); } }
private void OnWindowLoaded(object sender, RoutedEventArgs e) {
SetBinding(ActivePaneChangedProperty, new Binding { Source = DataContext, Path = new PropertyPath("ActivePaneChanged") });
...
}
private void OnActivePaneChanged(object sender, RoutedPropertyChangedEventArgs<ContentPane> e) { var activePane = xamDockManager.ActivePane; var context = DataContext as MyWindowViewModel;
if (activePane != null && ActivePaneChanged != null && ActivePaneChanged.CanExecute(activePane.Content) && context != null) { if (currentExplorerControl != activePane.Content && activePane.Content is IExplorerControl) { ActivePaneChanged.Execute(activePane.Content);currentTab = (IMyTabbedControl)activePane.Content; } } e.Handled = true; }
HTH