我找不到一个(肯定的)简单解决方案来解决一个简单的问题: 如果有以下XAML代码:
<StackPanel>
<Button Content="Item">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter"></i:EventTrigger>
<i:EventTrigger EventName="MouseLeave"></i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<ListBox Visibility="Collapsed"></ListBox>
</StackPanel>
我想在MouseEnter上显示列表框并隐藏在MouseLeave上。它可能只是一个单行,但我无法找到它。 非常感谢任何帮助。 谢谢!
答案 0 :(得分:0)
我相信这会照顾你的目标:
<StackPanel xmlns:local="clr-namespace:SilverlightApplication;assembly=SilverlightApplication">
<StackPanel.Resources>
<local:BoolToUIElementVisibilityConverter x:Name="BoolToUIElementVisibilityConv"/>
</StackPanel.Resources>
<Button Content="Item" x:Name="YourButton">
</Button>
<ListBox Visibility="{Binding Path=IsMouseOver, ElementName=YourButton, Converter={StaticResource BoolToUIElementVisibilityConv}}">
<ListBoxItem>a</ListBoxItem>
<ListBoxItem>b</ListBoxItem>
<ListBoxItem>c</ListBoxItem>
</ListBox>
</StackPanel>
上课:
using System.Windows.Data;
using System;
using System.Globalization;
using System.Windows;
namespace SilverlightApplication
{
public class BoolToUIElementVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value == true)
return Visibility.Visible;
else
return "Collapsed";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}