我有一个 WPF 项目,在其中我有一个Resource Dictionary
存储我的样式的地方。在这本词典中,我有一个ListBoxItem Template
看起来像这样的。
<DataTemplate x:Key="GenreStyle">
<Grid Width="150" Height="150" Background="Transparent">
<Image x:Name="GenreImage" Tag="{Binding Genre}" RenderOptions.BitmapScalingMode="HighQuality" Source="{Binding GenreSource}" Width="140" Height="140" MouseEnter="GenreImage_MouseEnter" MouseLeave="GenreImage_MouseLeave" MouseLeftButtonDown="GenreImage_MouseLeftButtonDown" MouseLeftButtonUp="GenreImage_MouseLeftButtonUp"/>
</Grid>
</DataTemplate>
现在我想做的是,Tag
当我点击每个项目时阅读图像。我现在做的是这样的:
private void StationsListLB_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var item = ItemsControl.ContainerFromElement(StationsListLB, e.OriginalSource as DependencyObject) as ListBoxItem;
if (item != null)
{
MessageBox.Show(??????);
}
}