我想绑定ItemContainerStyle中的Tag属性,但是不起作用
<controls:CoverView.ItemContainerStyle>
<Style TargetType="controls:CoverViewItem">
<Setter Property="Tag"
Value="{Binding Name}" />
<EventSetter Event="Selected" Handler="Cv_Selected"/>
<EventSetter Event="Deselected" Handler="Cv_Deselected"/>
<EventSetter Event="MouseDoubleClick" Handler="Cv_MouseDoubleClick"/>
</Style>
</controls:CoverView.ItemContainerStyle>
除了ItemContainerStyle绑定之外,它们都工作良好,但我需要在ItemContainerStyle中设置标记属性
更新: 这就是我获取标签值的方式
private void Cv_Selected(object sender, RoutedEventArgs e)
{
var item = sender as CoverViewItem;
MessageBox.Show(item.Tag.ToString());
}
这是xaml的完整代码
<controls:CoverView ItemsSource="{Binding Images}">
<controls:CoverView.ItemHeaderTemplate>
<DataTemplate>
<Image Source="{Binding ImageSource}"/>
</DataTemplate>
</controls:CoverView.ItemHeaderTemplate>
<controls:CoverView.ItemTemplate>
<DataTemplate>
<Border Margin="10">
<Image Source="{Binding ImageSource}"/>
</Border>
</DataTemplate>
</controls:CoverView.ItemTemplate>
<controls:CoverView.ItemContainerStyle>
<Style TargetType="controls:CoverViewItem">
<Setter Property="Tag"
Value="{Binding Name}" />
<EventSetter Event="Selected" Handler="Cv_Selected"/>
<EventSetter Event="Deselected" Handler="Cv_Deselected"/>
<EventSetter Event="MouseDoubleClick" Handler="Cv_MouseDoubleClick"/>
</Style>
</controls:CoverView.ItemContainerStyle>
</controls:CoverView>