2010-11-22 71 views
1

我有一些列表框,其中有此應用的風格:列表框項目樣式 - 如何顯示兩行中的項目..?

 <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> 

是否有可能以某種方式顯示兩行這些項目嗎?

回答

1

你應該在列表框ItemTemplate屬性做到這一點。在XAML看起來是這樣的:

<ListBox Width="300" ItemsSource="{Binding}"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel> 
        <TextBlock Text="{Binding Line1}" /> 
        <TextBlock Text="{Binding Line2}" /> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 

生成的列表框應該是這樣的:

alt text

當然,你不必使用一個StackPanel,你可以使用任何種類的佈局你就像在數據模板中一樣。有創意:)

相關問題