SyleProblem: Can't Change BackGround Of Particular button?

后端 未结 1 742
自闭症患者
自闭症患者 2021-01-25 01:17
  1. I have one ==> UserControl.
  2. Inside that UserControl ==> One ItemsControl.

    Now ItemsControl generating But

相关标签:
1条回答
  • 2021-01-25 02:08

    You are overwritting the Button's Template in your Style, so the Background color never gets used

    Default button template looks like this:

    <Button Background="SomeColor">
        <Button.Content>
    </Button>
    

    And you are overwritting the template to say

    <Border>
        <Button.Content>
    </Border>
    

    You need to bind the Border's Background color to the {TemplateBinding Background} so that it uses the Button's background color.

    I would also suggest using a DataTrigger instead of code behind to change the background color of the button.

    <Style TargetType="{x:Type Button}">
        <Setter Property="Background" Value="Transparent" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding }" Value="3">
                <Setter Property="Background" Value="Red" />
            </DataTrigger>
        </Style.Triggers>
    </Style>   
    
    0 讨论(0)
提交回复
热议问题