0

我正在为我的应用程序使用定义的 wpf 主题之一,因此我的所有控件都会自动根据该主题进行拉皮条。

现在我正在用项目(用户控件)填充列表框,但并非所有项目都应该始终可见。但是,当我将高度设置为 0(用户控件的)或设置为不可见时,我会得到列表框的粗灰色边框。

有人可以帮我覆盖 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>
4

2 回答 2

0

尽管不知道隐藏某些 ListBoxItems 的目的,但我可以给出使用 ListBoxItem 的 BorderThickness 或 BorderBrush 属性的想法。

<Setter Property="BorderThickness" Value="0" />

但如果你更好地解释你的场景,我可以在设计上提出一些建议。

于 2010-04-23T05:30:25.723 回答
0

好的,我想我设法解决了它。

我需要隐藏项目的原因是因为当更新时,它们可能会显示给用户,而不是重新填充列表框并再次询问电话中心。

我发现这并不是我需要设置的边界。灰色边框看起来好像是由边框属性设置的,但实际上它只是显示的背景,因为设置了边距。

<ContentPresenter Margin="5,3,3,3" />

重置此边距解决了我的问题。

无论如何感谢您的努力。

于 2010-04-23T06:56:42.317 回答