首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF命令按钮ListBoxItems

WPF命令按钮ListBoxItems
EN

Stack Overflow用户
提问于 2009-11-05 21:41:00
回答 2查看 2.3K关注 0票数 0

我有一个定义如下的列表框:

代码语言:javascript
复制
<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那样玩把戏吗?

EN

回答 2

Stack Overflow用户

发布于 2009-11-05 21:46:57

可能是因为绑定失败了。检查VS的输出窗口,查看是否有任何绑定错误。我怀疑LoadSimpleMoviePopupCommand属性不在您的数据项类上(即。您的Media类)。

票数 1
EN

Stack Overflow用户

发布于 2011-04-29 17:03:07

也有同样的问题,试试这个

代码语言:javascript
复制
<Button Command="{Binding DataContext.YourCommand,RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}"

这很正常,他在列表框中找不到您的命令绑定,因为您设置了如下内容

代码语言:javascript
复制
<DataTemplate DataType ...

所以他将在数据类型中查找绑定,而不是视图模型(我假设:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1680661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档