使用 CornerRadius 为 ListBox 自定义 Border 属性 [英] customize the Border property with CornerRadius for ListBox
问题描述
我想用 CornerRadius=5 自定义边框的以下 Listbox-display 属性.任何人都可以帮我实现它,而无需更改以下 Xaml 代码中的现有数据模板代码:
I want to customize the following Listbox-display property of border with CornerRadius=5..can anyone help me to achieve it without changing the existing datatemplate code in the following Xaml code:
<ListBox x:Uid="lst_value" Name="lstValues" Background="Wheat" BorderBrush="Black"
HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="1" Height="100" Width="150"
ItemsSource="{Binding listval}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Background="{Binding}">
<TextBlock x:Name="txtblk" Foreground="Black" FontSize="10" TextAlignment="Left"
FontWeight="Black" Text="{Binding}" Background="{Binding}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
推荐答案
如果你想让 ListBoxItems
中的 Border
有另一个 CornerRadius
值,您可以在定义 Border
的地方重新模板 ListBoxItem
,或者在 ItemContainerStyle
Resources
If you want the Border
within the ListBoxItems
to have another CornerRadius
value, you can either re-template ListBoxItem
where the Border
is defined, or set it implicitly in the ItemContainerStyle
Resources
<ListBox ...>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
</Style>
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
<!--...-->
</ListBox>
如果你想为 ListBox
设置 CornerRadius
,你可以做同样的事情,但在 Resources
而是
If you want to set CornerRadius
for the ListBox
, you can do the same but in Resources
instead
<ListBox ...>
<ListBox.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</ListBox.Resources>
<!--...-->
</ListBox>
这篇关于使用 CornerRadius 为 ListBox 自定义 Border 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!