tags:

views:

960

answers:

1

The following is a Simple Style for ListBoxItem, ListBoxItem has a son Border. Border has a Padding property with value of 8, I want to change the value to 0, when the item is selected. How can I write the trigger?

    <??Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}" >
                    <Border 
                        SnapsToDevicePixels="True" 
                        HorizontalAlignment="Center" 
                        VerticalAlignment="Center"
                        Padding = "8"
                        Background="{TemplateBinding Background}">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            ??<Setter Property="Padding" Value="0" />??   <----How Can I do this?
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    <??/Style>
+5  A: 

Try giving the Border a name (using, for example, x:Name="border1") then using the TargetName property of Setter, like this:

<Setter TargetName="border1" Property="Padding" Value="0" />

Not sure if it'll work in a control template like that, but give it a go.

Matt Hamilton