我在列表框中有一个按钮。我想将命令绑定到主网格的 DataContext。我不确定谁来做这件事,下面是我的尝试。
我想绑定到我的视图模型上的 ViewModel.SelectionEditorSelectionSelectedCommand,主网格绑定到,我不想绑定到实际的 filteredSelection.SelectionEditorSelectionSelectedCommand
这是我的 XAML
<Grid Name="MainGrid">
.....
<ListBox x:Name="MarketsListBox" Height="Auto" MaxHeight="80" ItemsSource="{Binding Path=FilteredMarkets}" Margin="5" Width="Auto" HorizontalAlignment="Stretch"
>
ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel Orientation="Horizontal">
<Button Height="Auto"
Content="{Binding FinishingPosition,Converter={StaticResource FinishingPositionToShortStringConverter1}}"
Foreground="{Binding Path=FinishingPosition, Converter={StaticResource FinishingPositionToColourConverter1}}"
Margin="2" Width="20"
Command="{Binding ElementName=MainGrid.DataContext, Path=SelectionEditorSelectionSelectedCommand}"
CommandParameter="{Binding}"
/>
.....