Wpf 列表框项目样式-如何在两行中显示项目。。?
我有一些listbox,它具有以下应用样式:Wpf 列表框项目样式-如何在两行中显示项目。。?,wpf,listbox,styles,listboxitem,Wpf,Listbox,Styles,Listboxitem,我有一些listbox,它具有以下应用样式: <Style x:Key="GroupListBoxItemStyle" TargetType="ListBoxItem"> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="FocusVisualStyle"
<Style x:Key="GroupListBoxItemStyle"
TargetType="ListBoxItem">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="FocusVisualStyle"
Value="{x:Null}" />
<Setter Property="FontSize"
Value="11" />
<Setter Property="FontWeight"
Value="Bold" />
<Setter Property="Width"
Value="95" />
<Setter Property="HorizontalAlignment"
Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<SlidingBar:SlidingBarRadioButton GroupName="PermissionsRadioButtonGroup"
IsChecked="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent},BindsDirectlyToSource=True,Mode=TwoWay}"
Text="{Binding Converter={StaticResource resourceStringToResourceConverter}}"
ImageSource="{Binding Converter={StaticResource PermissionTypeToImageConverter}}"
Margin="1"
/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
是否可以以某种方式将这些项目显示为两行?您应该在ListBox ItemTemplate属性中执行此操作。XAML看起来像这样:
<ListBox Width="300" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Line1}" />
<TextBlock Text="{Binding Line2}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
生成的列表框应如下所示:
当然,您不必使用StackPanel,您可以在数据模板中使用您喜欢的任何类型的布局。要有创意:)您应该在ListBox ItemTemplate属性中执行此操作。XAML看起来像这样:
<ListBox Width="300" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Line1}" />
<TextBlock Text="{Binding Line2}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
生成的列表框应如下所示:
当然,您不必使用StackPanel,您可以在数据模板中使用您喜欢的任何类型的布局。要有创意:)