0
我很困擾這一點,需要一些洞察力。當用戶鼠標懸停是一個ListBoxItem的我要顯示關於在其上的鼠標是目前在該項目的一些細節(希望我做的意義:()WPF ListBoxitem事件觸發器顯示彈出
爲了證明我是想達到什麼樣的請查看示例代碼
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>
現在,當用戶將鼠標懸停在列表框中的項目,我想顯示在彈出的customerphoto。
許多釷anks
P.S:代碼在編寫這篇文章時「熟了」,因此僅供演示。在列表框中會有多個項目,將鼠標懸停在每個項目上必須顯示與該對象關聯的照片。
有沒有辦法讓工具提示打開,直到鼠標懸停在物品上? –
您可以使用'TextBox'上的'ToolTipService.ShowDuration'來指定TextBox應該保持它的ToolTip打開的時間。如果無限價值是可能的,我並不積極,但我知道你可以將它設置成非常大的。 – Rachel