我正在为我的应用程序使用一个已定义的wpf主题,所以我的所有控件都会根据该主题自动进行拉伸操作。
现在我正在填充带有项目(usercontrols)的列表框,但并非所有这些项目都应始终可见。但是当我将高度设置为0(用户控制)或设置为不可见时,我得到了listboxitems的粗灰色边框。
有人可以帮我覆盖listboxitem的边框,或者告诉我模板中我需要更改边框的位置,因为我找不到它。
这是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>
答案 0 :(得分:0)
尽管不知道隐藏一些ListBoxItems的目的,我可以提出使用ListBoxItem的BorderThickness或BorderBrush属性的想法。
<Setter Property="BorderThickness" Value="0" />
但如果你更好地解释你的情景,我可以就设计提出建议。
答案 1 :(得分:0)
好吧,我想我设法解决了这个问题。
我需要隐藏项目的原因是因为更新后,它们可能会显示给用户,而不是重新填充列表框并再次询问电话中心。
我发现这不是我需要设置的边界。灰色边框看起来好像是由边框属性设置的,但它实际上只是因为设置了边距而显示的背景。
<ContentPresenter Margin="5,3,3,3" />
重置此保证金解决了我的问题。
无论如何,谢谢你的努力。