How to change the border on a listboxitem while using a predefined template

Posted by djerry on Stack Overflow See other posts from Stack Overflow or by djerry
Published on 2010-04-21T15:10:07Z Indexed on 2010/04/21 15:13 UTC
Read the original article Hit count: 598

Filed under:
|
|
|

Hey,

I'm using one of the defined wpf themes for my application, so all my controls automatically are pimped according to that theme.

Now i am filling a listbox with items (usercontrols), but not all of them should be visible at all time. But when i'm setting height to 0 (of usercontrol) or setting to invisible, i get a thick grey border of the listboxitems.

Can someone help me override the border of the listboxitem or show me where in the template i need to change the border, cause i just can't find it.

This is the part of the template for the listboxitem:

<Style d:IsControlPart="True" TargetType="{x:Type ListBoxItem}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="false"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <ControlTemplate.Resources>
                    <Storyboard x:Key="HoverOn">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="HoverRectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                    <Storyboard x:Key="HoverOff">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="HoverRectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                    <Storyboard x:Key="SelectedOn">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SelectedRectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                    <Storyboard x:Key="SelectedOff">
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="SelectedRectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </ControlTemplate.Resources>
                <Grid Background="{TemplateBinding Background}"
                    Margin="1,1,1,1" SnapsToDevicePixels="true" x:Name="grid">
                    <Rectangle x:Name="Background"
                        IsHitTestVisible="False"
                        Fill="{StaticResource SelectedBackgroundBrush}"
                        RadiusX="0"/>
                    <Rectangle x:Name="SelectedRectangle"
                        IsHitTestVisible="False"
                        Opacity="0"
                        Fill="{StaticResource NormalBrush}"
                        RadiusX="0"/>
                    <Rectangle x:Name="HoverRectangle"
                        IsHitTestVisible="False"
                        Fill="{StaticResource HoverBrush}"
                        RadiusX="0"
                        Opacity="0"/>
                    <ContentPresenter Margin="5,3,3,3" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" x:Name="contentPresenter"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Trigger.EnterActions>
                            <BeginStoryboard Storyboard="{StaticResource HoverOn}"/>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <BeginStoryboard Storyboard="{StaticResource HoverOff}"/>
                        </Trigger.ExitActions>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="true">
                        <Trigger.EnterActions>
                            <BeginStoryboard Storyboard="{StaticResource SelectedOn}"/>
                        </Trigger.EnterActions>
                        <Trigger.ExitActions>
                            <BeginStoryboard Storyboard="{StaticResource SelectedOff}"/>
                        </Trigger.ExitActions>
                    </Trigger>

                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}"/>
</Style>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml