WPF 命令按钮 ListBoxItems
我有一个如下定义的列表框:
<ListBox x:Name="lstMedias" ItemsSource="{Binding Medias}" Width="Auto" Height="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}" Tag="{Binding Name}" Click="Button_Click" Command="{Binding Path=LoadSimpleMoviePopupCommand}">
<Button.Resources>
<Converters:LoadMovieMultiConverter x:Key="LoadMovieMultiConverter" />
</Button.Resources>
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource LoadMovieMultiConverter}">
<MultiBinding.Bindings>
<Binding ElementName="DragDropCanvas" />
<Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
</MultiBinding.Bindings>
</MultiBinding>
</Button.CommandParameter>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
当尝试调用命令 LoadSimpleMoviePopupCommand 时,不会调用命令,但在调用单击事件时,会引发事件。
你知道为什么吗?这是正常行为吗?我们是否必须像 ListBoxItem doubleclick 那样欺骗?
I Have a listbox defined like below :
<ListBox x:Name="lstMedias" ItemsSource="{Binding Medias}" Width="Auto" Height="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}" Tag="{Binding Name}" Click="Button_Click" Command="{Binding Path=LoadSimpleMoviePopupCommand}">
<Button.Resources>
<Converters:LoadMovieMultiConverter x:Key="LoadMovieMultiConverter" />
</Button.Resources>
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource LoadMovieMultiConverter}">
<MultiBinding.Bindings>
<Binding ElementName="DragDropCanvas" />
<Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
</MultiBinding.Bindings>
</MultiBinding>
</Button.CommandParameter>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
When Trying to call command LoadSimpleMoviePopupCommand, command is not called, but when calling click event, event is raised.
Do You have an idea why ? It is a normal behavior ? Do we have to trick like ListBoxItem doubleclick ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是因为绑定失败。检查VS的输出窗口,看看是否有绑定错误。我怀疑
LoadSimpleMoviePopupCommand
属性不在您的数据项类(即您的Media
类)上。Probably because the binding failed. Check the output window of VS and see if there are any binding errors. I suspect the
LoadSimpleMoviePopupCommand
property is not on your data item class (ie. yourMedia
class).遇到了同样的问题,尝试一下,这
很正常,他在列表框中找不到您的命令绑定,因为您
在该列表框中设置了类似的内容,所以他将在数据类型而不是视图模型中查找该绑定(我假设: )
had the same problem, try this
it's quite normal, he can't find your command binding inside the listbox because you set something like
in that listbox so he'll be looking for that binding inside the datatype and not the viewmodel (I assume :)