我正在创建自定义工具窗口并将其添加到我的 userControl。UserControl 是自定义停靠窗口和工具窗口的元素。所以在我的 mainWindow xaml 我有 DataTemplate
<DataTemplate DataType="{x:Type viewModels:PropertyGridToolWindowViewModel}">
<views:PropertyGridToolWindowView/>
</DataTemplate>
我正在设置包含所有 toolWindows 和 DocumentWindows 的 userControl,例如:
<ContentControl Content="{Binding}" x:Name="CustomContentControl"/>
我的自定义 toolWindow xaml 代码如下所示:
<Grid>
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Dock="Right">
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Dock="Top" >
<Grid>
<Button Name="SaveBtn" Content=" Save " IsEnabled="{Binding SaveButtonIsEnabled}" Grid.Column="0" Command="{Binding SaveClickCommand}" CommandParameter="{Binding ElementName=PropertiesUserControl}"/>
<Button Name="EditBtn" Content=" Edit " Grid.Column="1" HorizontalAlignment="Stretch" Command="{Binding EditClickCommand}" IsEnabled="{Binding EditButtonIsEnabled}"/>
<Button Name="CancelBtn" Content=" Cancel " Grid.Column="2" HorizontalAlignment="Stretch" Command="{Binding CancelClickCommand}" IsEnabled="{Binding CancelButtonIsEnabled}"/>
</Grid>
</DockPanel>
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Dock="Bottom">
<shared:PixelSnapper>
<propgrid:PropertyGrid SelectedObject="{Binding SelectedObject}">
</propgrid:PropertyGrid>
</shared:PixelSnapper>
</DockPanel>
</DockPanel>
</Grid>
我的 toolWindows 和 documentWindows 的 customUserControl 是:
<docking:DockSite x:Name="dockSite" viewModels:DockSiteViewModelBehavior.IsManaged="true" CanDocumentWindowsRaft="True" ItemContainerRetentionMode="Wrapped"
DocumentItemsSource="{Binding DocumentItems}" DocumentItemContainerStyle="{StaticResource DocumentItemStyle}"
ToolItemsSource="{Binding ToolItems}" ToolItemContainerStyle="{StaticResource ToolItemStyle}">
<docking:DockSite.AutoHideRightContainers>
<docking:ToolWindowContainer>
<views:PropertyGridToolWindow CanClose="False" HasOptions="False"/>
</docking:ToolWindowContainer>
</docking:DockSite.AutoHideRightContainers>
<docking:Workspace x:Name="Workspace>
<docking:TabbedMdiHost />
</docking:Workspace>
</docking:DockSite>
如您所见,我在 xaml 中添加了 toolWindow 并且它以正确的方式显示。但我需要动态创建这个 toolWindow。还有问题。当我动态创建相同的工具窗口时,它不会显示我的自定义工具窗口的停靠面板。我该如何解决这个问题?提前致谢
编辑我创建工具的方式Windows
var toolWindow = new PropertyGridToolWindowViewModel();
toolWindow.Title = "Another ToolWindow";
_toolItems.Add(toolWindow);
问题是没有创建视图。但我不明白为什么...