I have a class ExpanderItems
which gets loaded during runtime and a list of these is set as the DataContext
of a ListBox
. Now what I want to do is show the corresponding Images as a Tooltip
for each Item. Any suggestions how to do that?
public class ExpanderItem
{
private String mItemName = "empty";
public String ItemName
{
get { return mItemName; }
set { mItemName = value; }
}
private Image mItemSymbol = null;
public Image ItemSymbol
{
get { return mItemSymbol; }
set { mItemSymbol = value; }
}
}
public List<ExpanderItem> getExpanderItems()
{
List<ExpanderItem> ItemList = new List<ExpanderItem>();
ExpanderItem i0 = new ExpanderItem();
i0.ItemName = "Constant";
i0.ItemSymbol = new Image();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"/resources/Constant.png", UriKind.RelativeOrAbsolute);
bi.EndInit();
i0.ItemSymbol.Source = bi;
ItemList.Add(i0);
...
}
In the Window where the Items are used I am calling:
void WindowMain_Loaded(object sender, RoutedEventArgs e)
{
lbItems.DataContext = SomeService.getExpanderItems();
}
XAML Looks like:
<ListBox x:Name="lstItems" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding ItemName}">
</Label>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>