Home > Net >  WPF through triggers change Border BorderBrush attribute is invalid
WPF through triggers change Border BorderBrush attribute is invalid

Time:11-27

 & 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 round

Simple solution is to write and attributes related to trigger the ControlTemplate. Triggers, please look at the code

 

<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>
nullnullnullnull
  •  Tags:  
  • C#
  • Related