wpf listview问题。listview中如何实现鼠标移动到某一行,该行中的button属性变为可见
展开全部
第一眼看到这个问题想到的是EventTrigger,可试了下发现没法实现
不过用了别的方法实现了如下
<ListView ItemsSource="{Binding User}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" MouseEnter="StackPanel_MouseEnter" MouseLeave="StackPanel_MouseLeave" Background="AntiqueWhite" Width="100">
<TextBlock Text="{Binding id}"/>
<Button Content="{Binding userName}" Visibility="Collapsed"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
下面是两个后台方法
private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
{
StackPanel sp = sender as StackPanel;
Button b = sp.Children.OfType<Button>().First();
b.Visibility = Visibility.Visible;
}
private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
{
StackPanel sp = sender as StackPanel;
Button b = sp.Children.OfType<Button>().First();
b.Visibility = Visibility.Collapsed;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询