& lt; Window. Resources>
<style TargetType="ListBox" & gt;
<style TargetType="ListBoxItem" & gt;
<style>
<style. Triggers>
</style>
<style>
<style. Triggers>
</style>
<style. Triggers>
</style>
</style>
Code above line 15, when the listbox listboxitem selected inside, want to change the color of the border, but there is no effect, but the shrinkage of the stackpanel effect, ask why is this so?
CodePudding user response:
Why it's hard for me to say with you write not trigger in Style, but can tell you are recommended to write the ControlTemplate. Triggers, I saw you. The code above is to add the ControlTemplate Triggers, but don't know why, by means of Style and binding up this way get the need to pay attention to something a little more, and a little roundSimple solution is to write and attributes related to trigger the ControlTemplate. Triggers, please look at the code
nullnullnullnull
<style TargetType="ListBox" & gt;
<style TargetType="ListBoxItem" & gt;
<style. Triggers>
</style>
Background="{Binding RelativeSource={RelativeSource FindAncestor=Mode, AncestorType=ListBoxItem}, Path=Background}"
Text="{Binding Path=Name}"/& gt;
</style>