StackPanel Binding

注意<i:Interaction>需要使用Blend的System.Windows.Interactivity.dll文件。

Xaml文件:

<StackPanel Width="200" Height="auto" MaxHeight="400" Grid.Row="1">
  <ItemsControl ItemsSource="{Binding MenuSet}">
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
      <StackPanel HorizontalAlignment="Center" IsItemsHost="True"></StackPanel>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding Name}" Name="txtb">
        <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
    

          <i:InvokeCommandAction CommandParameter="{Binding ElementName=txtb}"
          Command="{Binding Path=DataContext.ModifyCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type            StackPanel}}}">

        </i:InvokeCommandAction>

        </i:EventTrigger>
        </i:Interaction.Triggers>
      </TextBlock>
    </DataTemplate>
  </ItemsControl.ItemTemplate>
 </ItemsControl>
</StackPanel>

 

 

ViewModel: 注意DelegateCommand需要Prism中的Microsoft.Practices.Prism.dll。

Model:

原文地址:https://www.cnblogs.com/gnsds/p/3632259.html