0

私はこれにかなり行き詰まっており、洞察が必要です。ユーザーのマウスオーバーがリストボックスアイテムの場合、マウスが現在上にあるアイテムに関する詳細を表示したい(意味があることを願っています:()

私が達成したいことを実証するには、サンプルコードを参照してください

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>

ユーザーがリストボックスの項目にカーソルを合わせたときに、顧客の写真をポップアップで表示したいと考えています。

どうもありがとう

PS: コードはこの投稿を書いている間に「調理」されたので、デモ専用です。リストボックスには複数のアイテムがあり、各アイテムにカーソルを合わせると、そのオブジェクトに関連付けられた写真が表示されます。

4

1 に答える 1

0

を使用しないのはなぜToolTipですか?WPF では、ツールヒントはテキストのみである必要はありません

<TextBlock.ToolTip>
    <ToolTip>
        <Image Source="{Binding CustomerPhoto}" />
    </ToolTip>
</TextBlock.ToolTip>
于 2011-10-24T14:01:50.440 に答える