Background is not recognized in triggers

纵然是瞬间 提交于 2020-03-28 06:54:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!