gridview 选中某行后 某行的按钮显示,无选中则隐藏

如后面的加号,选中行时出现,未被选中的隐藏

解决:

在按钮中的visibility属性中绑定该item是否选中,再用转换器转换

    <Button Name="btnA" Click="btnA_Click_1" BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Visibility="{Binding RelativeSource={RelativeSource AncestorType=ListViewItem}, Path=IsSelected,Converter={StaticResource btnshowConverter}}">+</Button>

 

 

public class btnshowConverter : IValueConverter
 {
       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
             if (value.ToString() == "True") return "Visible";
             if (value.ToString() == "False") return "Collapsed";
             return value;
      }
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
     {
             throw new NotImplementedException();
     }
}

posted @ 2019-04-27 12:05  岳凯歌  阅读(175)  评论(0编辑  收藏  举报