我试图让我的头脑围绕 WPF 模型。
我有一个项目列表框。列表框内的项目是字符串标识符。这工作正常。我想要的是拥有它,以便在封闭控件的代码隐藏中可以访问当前所选项目的标识符。
我有这个:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="320">
<Label Content="{Binding Path=ShortName}" Style="{StaticResource ListHeader}"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Path=Description}" Style="{StaticResource ListText}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
我想我应该添加类似的内容:
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
<Setter Property="" TargetName="">
<Setter.Value>
</Setter.Value>
</Setter>
</DataTrigger>
但是我不知道如何设置设置器来设置作为封闭控件一部分的属性(即外部世界)。我想我有这个倒退?