问题
After asking a question here before someone suggested moving it to the XAML, for designer esthetics. Which after reviewing my code I agreed. Since I can change my colors in my color dictionary and not worry about that chunk of code.
So what I've done in my user control was to add a trigger/datatrigger? to the border which accepts the background color.
<Border.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Type, ElementName=AlertWindow}" Value="Caution">
<Setter Property="Background" Value="{StaticResource AlertBlue}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
Type should be written as follows
<usercontrol:alerts Type="Caution" Title="Careful"></usercontrol:alerts>
Though I'm getting an error that Background
is not recognized and after trying multiple different bindings I'm not getting anything.
Note** I am new to bindings and triggers so I've been trying to read through SO and much of what I've found and have tried is not working.
Basically I want the trigger to sort out the different color opportunities for the Border. So there's four Caution
, Success
, Info
and Warning
each of which will have their own colors. And I like this method because then I can use these to change more of the usercontrol itself and not have multiple code behind functions to make them more unique.
来源:https://stackoverflow.com/questions/60658481/background-is-not-recognized-in-triggers