1. 程式人生 > >gridview 選中某行後 某行的按鈕顯示,無選中則隱藏

gridview 選中某行後 某行的按鈕顯示,無選中則隱藏

con alt tor string glob obj item 出現 nsh

技術分享圖片

如後面的加號,選中行時出現,未被選中的隱藏

解決:

在按鈕中的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();
}
}

gridview 選中某行後 某行的按鈕顯示,無選中則隱藏