我想创建一个这样的列表框:
- - - - | - - - - | - - - - | - - - - | - - - - | - - - -
这是我使用边距分隔的listboxitems。这很好用。我想要的是列表框有一个包含这一行的背景。或者至少在后台拥有它。我尝试了一个分隔符,但这不是我想要的,因为它也是可点击的,因为我在itemtemplate中使用它。
有什么想法吗?
由于
答案 0 :(得分:0)
您必须将带有控件模板的样式添加到ListBox项目。
<Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="Border"
BorderThickness="1,0"
BorderBrush="Black"
Padding="2"
SnapsToDevicePixels="true">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 1 :(得分:0)
边框控件适用于此类装饰线。侧面的厚度是独立设置的,因此只使用一侧用于单条垂直线。在相关的说明中,您是否尝试过使用Grid控件作为布局而不是边距?
答案 2 :(得分:0)
我正在尝试创建一个像控件一样的时间轴。我现在用它来解决它:
<ListBox.Template>
<ControlTemplate>
<Border BorderThickness="2" BorderBrush="Black">
<Grid>
<Rectangle Height="2" HorizontalAlignment="Stretch" VerticalAlignment="Center" Fill="Black"/>
<ScrollViewer Padding="{TemplateBinding Padding}">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</ListBox.Template>
这在testproject中运行良好,但我的主项目中遇到了一些问题。矩形保留在滚动查看器下方。嗯......取得进展。希望尽快解决这个问题。
到目前为止,感谢您的回答!