【问题标题】:WPF Listboxitem event trigger show popupWPF Listboxitem 事件触发器显示弹出窗口
【发布时间】:2011-10-24 22:09:32
【问题描述】:

我非常坚持这一点,需要一些见解。当用户鼠标悬停是一个列表框项时,我想显示一些有关鼠标当前所在项目的详细信息(希望我说得通:()

要演示我想要实现的目标,请查看示例代码

public class Customer
{
    public String FirstName { get; set; }
    public Image CustomerPhoto { get; set; }

    public Customer(String firstName, Image customerPhoto)
    {
        this.FirstName = firstName;
        this.CustomerPhoto = customerPhoto;
    }

}

public class Customers : ObservableCollection<Customer>
{
    public Customers()
    {
        Image simpleImage = new Image();    
        BitmapImage bi = new BitmapImage();
        bi.BeginInit();
        bi.UriSource = new Uri(@"c:\image.jpg",UriKind.RelativeOrAbsolute);
        bi.EndInit();
        simpleImage.Source = bi; 
        Add(new Customer("Customer", simpleImage));
    }
}

XAML

<ListBox ItemsSource="{StaticResource customers}">
  <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding FirstName}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

现在,当用户将鼠标悬停在列表框项目上时,我想在弹出窗口中显示客户照片。

非常感谢

P.S:写这篇文章的时候代码是“煮熟的”,所以只用于演示。列表框中将有多个项目,将鼠标悬停在每个项目上必须显示与该对象关联的照片。

【问题讨论】:

    标签: wpf popup listboxitem eventtrigger


    【解决方案1】:

    为什么不直接使用ToolTip?在 WPF 中,工具提示不必是纯文本的

    <TextBlock.ToolTip>
        <ToolTip>
            <Image Source="{Binding CustomerPhoto}" />
        </ToolTip>
    </TextBlock.ToolTip>
    

    【讨论】:

    • 有没有办法让工具提示保持打开直到鼠标悬停在项目上?
    • 您可以使用TextBox 上的ToolTipService.ShowDuration 来指定文本框应保持其工具提示打开的时间。如果无限值是可能的,我不肯定,但我知道您可以将其设置为非常大的值。
    猜你喜欢
    • 2013-07-13
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 2020-11-28
    • 2016-08-20
    • 1970-01-01
    • 2017-10-16
    • 2016-06-22
    相关资源
    最近更新 更多