Avinash Reddy
Avinash Reddy

Reputation: 937

Setting the Template Background from style

I have a style like this

<Style x:Key="LeavesStyle" TargetType="{x:Type dxe:ListBoxEditItem}">
            <Setter Property="Background" Value="Blue" />//Not Working
            <Setter Property="Template" Value="{StaticResource ItemTemplate}">
            </Setter>
        </Style>

and my Template

<ControlTemplate x:Key="ItemTemplate" TargetType="{x:Type dxe:ListBoxEditItem}">
            <Border x:Name="rootBorder" BorderThickness="0,0,0,1" BorderBrush="{dxi:ThemeResource ThemeKey={dxgt:GridRowThemeKey ResourceKey=GridDataRowDelimiterBrush}}">

How can I access the rootBorder from Background from style? to set the rootBorders Background

I know I can do like this <Setter TargetName="rootBorder" Property="Background" Value="Orange" />

inside my template, I wanna do this from style Please help stuck here from so long

Upvotes: 0

Views: 84

Answers (2)

Tobias Hoefer
Tobias Hoefer

Reputation: 1128

The Background property is not applied automatically to your border. You need to link the borders background to the background property of your control. You can do that using a TemplateBinding:

 <ControlTemplate>
     <Border Background="{TemplateBinding Background}" />
 </ControlTemplate>

Changing the Background property of the control in your style will now change the background of your item.

Upvotes: 1

programmer444
programmer444

Reputation: 156

One possibility would be to override the controltemplate in style and add the border in it

You can see a similiar solutiom here: WPF ListView Style Borders

Upvotes: 0

Related Questions