
I am actually quite surprised to find that this doesn't work, but quite frankly considering WPF's major push for this pattern, it almost essential that it works. Now, for what doesn't seem to work....
I have a main window that has a dock site and I want to be able to add new tabs to it. Notice the "ItemsSource" binding. The DataContext of the window is set to a viewmodel that defines the "Workspaces" property....Now, we have a user control that is our "view" that we want to display in each tab, and it also has it's datacontext set to a viewmodel...
Now, we define a data template for the UserControlViewModel type that tells WPF how to display the UserControlViewModel type...
As you can see, the data template tells WPF to render a UserControlViewModel as a docking:ToolWindow with it's content as the UserControl.
Then in the ViewModel we simply define the "Workspaces" property, and a method to add / remove from it...Now, when we add a new workspace, WPF goes "oh, I know how to display that (as a toolwindow), and pops a new one into the TabbedMdiContainer's items.
This should work (it does with a tab control), and really needs to work in order for this great control to really fit with the WPF process. However it throws an error that "UserControlViewModel" cannot be added to a TabbedMdiContainer.
[Modified at 03/05/2009 08:16 AM]
I have a main window that has a dock site and I want to be able to add new tabs to it. Notice the "ItemsSource" binding. The DataContext of the window is set to a viewmodel that defines the "Workspaces" property....
<ribbon:RibbonWindow>
<Grid>
<docking:DockSite Grid.Column="2">
<docking:Workspace>
<docking:TabbedMdiHost>
<docking:TabbedMdiContainer IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Workspaces}">
</docking:TabbedMdiHost>
</docking:Workspace>
</docking:DockSite>
</ribbon:RibbonWindow>
</Grid>
<UserControl x:Class="MyUserControl">
<Some content here bound to my view model/>
</UserControl>
public class UserControlViewModel : INotifyPropertyChanged
{
blah, blah, blah...properties the above user control can bind to
}
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ViewModels="ViewModels"
xmlns:UserControls="UserControls"
xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes"
xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
>
<DataTemplate DataType={x:Type UserControls:UseMyrControl}>
<docking:ToolWindow Title="{Binding Title}" ImageSource="{StaticResource Image}">
<UserControls:MyUserControl />
</docking:ToolWindow>
</DataTemplate>
</ResourceDictionary>
Then in the ViewModel we simply define the "Workspaces" property, and a method to add / remove from it...
public class MainWindowViewModel
{
public ObservableCollection<UserControlViewModel> Workspaces {get; set;}
public void AddWorkspace(UserControlViewModel workspace)
{
Workspaces.Add(workspace);
}
}
This should work (it does with a tab control), and really needs to work in order for this great control to really fit with the WPF process. However it throws an error that "UserControlViewModel" cannot be added to a TabbedMdiContainer.
[Modified at 03/05/2009 08:16 AM]