toolkit:Accordion DataTemplate ListBox TextBlock Interaction.Triggers

困扰好几个小时的问题终于解决了,本人系菜鸟,使用MVVM设计模式,绑定DataTemplate的Command,需要使用

DataContent的资源,否则无法触发ICommand ClickChildMenu

下面是关键代码:

<TextBlock   Text="{Binding Title}" FontSize="12" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp" >
<i:InvokeCommandAction
Command="{Binding ElementName=LayoutRoot,
Path=DataContext.ClickChildMenu}"
CommandParameter="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
<toolkit:Accordion x:Name="theList" SelectionMode="ZeroOrOne"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontSize="12"  ItemsSource="{Binding Catalog}">
<toolkit:Accordion.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding CatalogName}" FontSize="12" />
</StackPanel>
</DataTemplate>
</toolkit:Accordion.ItemTemplate>
<toolkit:Accordion.ContentTemplate>
<DataTemplate>
<ListBox x:Name="mListBox" ItemsSource="{Binding ChildMenus}" BorderThickness="0" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" FontSize="12" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp" >
<i:InvokeCommandAction
Command="{Binding Source={StaticResource vm},
Path=ClickChildMenu}"
CommandParameter="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate> </ListBox>
</DataTemplate>
</toolkit:Accordion.ContentTemplate>
</toolkit:Accordion>
上一篇:一、Git的一些命令操作----创建版本库、增加文件到Git库、时光机穿梭、远程仓库


下一篇:cocos2d-x一些核心概念截杀