列表框wp7中按钮的事件触发器 [英] Event trigger for buttons inside listbox wp7

查看:68
本文介绍了列表框wp7中按钮的事件触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,

这是我的mainpage.xml部分的外观

  <   ListBox     x:名称  = 列表  
ItemsSource = {Binding ListItemsSource} >
< ListBox.ItemTemplate >
< DataTemplate >
< StackPanel >
< TextBlock 文字 = {Binding Name} FontSize = 30 / >
< 按钮 < span class =code-attribute>内容 = x:名称 = btnLike IsEnabled = {Binding Like,Mode = TwoWay} >

< i:Interaction.Triggers >
< i:EventTrigger EventName = 点击 >
< i:InvokeCommandAction 命令 = {Binding SetLikeButtonCommand}
< span class =code-attribute> CommandParameter = {Binding Path = DataContext,ElementName = btnLike} / >
< / i:EventTrigger >
< / i:Interaction.Triggers >

< /按钮 >
< / StackPanel > ;
< / DataTemplate >
< / ListBox.ItemTemplate >
< i:Interaction.Triggers >
< i:EventTrigger EventName = SelectionChanged >
< i:InvokeCommandAction 命令 = {Binding SetCountryIdCommand}
CommandParameter = {Binding Path = SelectedItem,ElementName = List} / >
< / i:EventTrigger >
< / i:Interaction.Triggers >
< / ListBox >







我的问题是事件触发器(单击)不触发按钮。

但另一方面ListBox事件触发器( SelectionChanged )工作正常。



请帮帮我,什么我的代码有问题吗?

解决方案

ListBox没有点击事件。

http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.aspx [ ^

Hello All,
This is How my part of mainpage.xml looks

<ListBox x:Name="List"
                    ItemsSource="{Binding ListItemsSource}">
               <ListBox.ItemTemplate>
                   <DataTemplate>
                       <StackPanel>
                               <TextBlock Text="{Binding Name}"  FontSize="30" />
                               <Button Content="Like" x:Name="btnLike" IsEnabled="{Binding Like,Mode=TwoWay}"  >

                                   <i:Interaction.Triggers>
                                       <i:EventTrigger EventName="Click">
                                           <i:InvokeCommandAction Command="{Binding SetLikeButtonCommand}"
                                              CommandParameter="{Binding Path=DataContext, ElementName=btnLike}"/>
                                       </i:EventTrigger>
                                   </i:Interaction.Triggers>

                           </Button>
                       </StackPanel>
                   </DataTemplate>
               </ListBox.ItemTemplate>
               <i:Interaction.Triggers>
                   <i:EventTrigger EventName="SelectionChanged">
                       <i:InvokeCommandAction Command="{Binding SetCountryIdCommand}"
                                              CommandParameter="{Binding Path=SelectedItem, ElementName=List}"/>
                   </i:EventTrigger>
               </i:Interaction.Triggers>
           </ListBox>




My Problem is Event Trigger (Click)for button is not fired.
But in other hand ListBox Event trigger (SelectionChanged) is working fine.

Please help me ,What is the problem with my code ?

解决方案

There is no click event for the ListBox.
http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.aspx[^]


这篇关于列表框wp7中按钮的事件触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆