【问题标题】:How to show button when the user clicks a listbox item?当用户单击列表框项目时如何显示按钮?
【发布时间】:2012-03-05 09:02:03
【问题描述】:

我正在检查这个窗口。它有一个列表框,当您单击一个项目时,它会显示三个按钮。

我想在我的程序中实现类似的东西。我该怎么做?

【问题讨论】:

    标签: c# wpf templates triggers styles


    【解决方案1】:

    您可以通过使用BooleanToVisibilityConverter 直接绑定Visibility 或使用DataTrigger 来绑定到项目的IsSelected

    1. 直接绑定

      <ListBox.Resources>
          <BooleanToVisibilityConverter x:Key="b2v"/>
      </ListBox.Resources>
      
      <ListBox.ItemTemplate>
          <DataTemplate>
              <!-- ... -->
              <Button Visibility="{Binding IsSelected,
                                           RelativeSource={RelativeSource AncestorType=ListBoxItem},
                                           Converter={StaticResource b2v}}".../>
          </DataTemplate>
      </ListBox.ItemTemplate>
      
    2. 样式和数据触发器

      throw new NotImplementedException();
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多