2012-11-12 42 views
0

我不能找到一個(肯定的),一個簡單的問題,簡單的解決方案: 如果有以下XAML代碼:Silverlight的化妝列表框上的按鈕懸停可見

<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

我相信這會做你所追求的:

<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(); 
     } 
    } 
}