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:

posted @ 2014-03-29 11:03  巩乃斯大叔  阅读(383)  评论(0编辑  收藏  举报