简体   繁体   中英

How to show button when the user clicks a listbox item?

I was checking this window. It has a listbox, and when you click an item, it shows three buttons.

I want to implement something similar in my program. How can I do that?

在此处输入图片说明

You can bind to the IsSelected of the item, either by directly binding the Visibility using a BooleanToVisibilityConverter or by employing a DataTrigger .

  1. Direct Binding

     <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. Style & DataTrigger

     throw new NotImplementedException(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM