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>
Despite not knowing the purpose of hiding some ListBoxItems, I could give the idea of using the BorderThickness or BorderBrush property of ListBoxItem.
<Setter Property="BorderThickness" Value="0" />
But if you explain your scenario better, i could suggest something on the design.
Ok i think i managed to fix it.
The reason i needed to hide items is because when updated, they might be shown to the user rather then refilling the listbox and interrogating the telephone center again.
I've found that is wasn't really a border i needed to set. The gray border looked as if it was set by a border attribute, but it really just was the background that showed because a margin was set.
<ContentPresenter Margin="5,3,3,3" />
Resetting this margin solved my problem.
Thanks anyways for the effort(s).
精彩评论