WPFアプリケーションの構築に複合アプリケーションガイダンスパターンを使用しています。私のシェルには、ビューを領域に動的にロードするための領域を含むタブコントロールがあります。ビューは、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です。
<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>
誰かがこのバインディングの問題を解決する方法を知っていますか?