【问题标题】:Silverlight make listbox visible on button hoverSilverlight 使列表框在按钮悬停时可见
【发布时间】:2012-11-14 01:08:57
【问题描述】:

对于一个简单的问题,我找不到(肯定)简单的解决方案: 如果有以下 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 隐藏。它可能只是一个单线,但我找不到它。 任何帮助都深表感谢。 谢谢!

【问题讨论】:

    标签: silverlight xaml


    【解决方案1】:

    我相信这会满足您的需求:

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

    【讨论】:

      猜你喜欢
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多