我正在使用复合应用程序指导模式来构建我的 WPF 应用程序。在我的 Shell 中,我有一个 tabcontrol,其中包含一个用于将视图动态加载到该区域的区域。视图被加载到 TabControl 中的新选项卡中。
<TabControl
AutomationProperties.AutomationId="MainTabControl"
cal:RegionManager.RegionName="{x:Static inf:RegionNames.MainRegion}"
Width="Auto" Height="Auto" Margin="10,10,0,0"
HorizontalAlignment="Stretch"
IsSynchronizedWithCurrentItem="True"
ItemTemplate="{StaticResource TabItemTemplate}"
SelectionChanged="TabControl_SelectionChanged">
我有一个用于实现 CloseButton 的 DataTemplate“TabItemTemplate”。我不知道如何将 DataTemplate 中的按钮命令绑定到 PresentationModel 中的关闭命令。如果我将命令绑定到 CompositCommand,则执行该命令。但随后我必须找出关闭按钮被按下的选项卡,并且只在该 PresentationModel 中执行 closeCommand。下面是数据模板。
<DataTemplate x:Key="ClosableTabItemTemplate">
<DockPanel Width="120">
<Button
Command="inf:CloseCommands.CloseCommand"
Content="X"
Cursor="Hand"
DockPanel.Dock="Right"
Focusable="False"
FontFamily="Courier"
FontSize="9"
FontWeight="Bold"
Margin="0,1,0,0"
Padding="0"
VerticalContentAlignment="Bottom"
Width="16" Height="16"
/>
<ContentPresenter
Content="{Binding}"
VerticalAlignment="Center"
/>
</DockPanel>
</DataTemplate>
有谁知道如何解决这个绑定问题?