0

我需要爲我的WP7應用程序提供兩行列表框項目,一行是標題,然後是一些較小的子標題和一些細節。我如何在WP7中做到這一點?列表框項目模板中的多個文本行?

我正在使用VS2010和表達式混合來製作我的應用程序,並且目前我有一個單個列表框項目(文本)的自定義樣式和項目模板。

這是到目前爲止我的代碼

<phone:PhoneApplicationPage.Resources> 
     <ItemsPanelTemplate x:Key="ItemsPanelTemplate1"> 
      <StackPanel Margin="0,20" HorizontalAlignment="Center"> 
       <StackPanel.Resources> 
        <Style TargetType="ListBoxItem"> 
         <Setter Property="HorizontalContentAlignment" Value="Center"/> 
        </Style> 
       </StackPanel.Resources> 
      </StackPanel> 
     </ItemsPanelTemplate> 
     <Style x:Key="ListBoxStyle1" TargetType="ListBox"> 
      <Setter Property="Background" Value="Transparent"/> 
      <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/> 
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/> 
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="BorderThickness" Value="0"/> 
      <Setter Property="BorderBrush" Value="Transparent"/> 
      <Setter Property="Padding" Value="0"/> 
      <Setter Property="HorizontalAlignment" Value="Center"/> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="ListBox"> 
         <ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="#FF82C12E" Padding="{TemplateBinding Padding}" HorizontalAlignment="Center" FontSize="48"> 
          <ItemsPresenter HorizontalAlignment="Center"/> 
         </ScrollViewer> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </phone:PhoneApplicationPage.Resources> 

感謝您的幫助!

回答

2

你可以有一個ItemTemplate:

<DataTemplate x:Key="MyItemTemplate"> 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 
      <TextBlock Grid.Row="0"/> 
      <TextBlock Grid.Row="1"/> 
     </Grid> 
    </DataTemplate> 

而在你的列表框綁定屬性:

<ListBox ItemTemplate="{StaticResource MyItemTemplate}"/> 
+0

謝謝,我會如何填充ListBox中的兩個的TextBlocks?目前我使用的字符串列表作爲項目來源 – 2013-04-28 23:49:48

+0

那麼如果你的ItemSource是一個列表你只能綁定一個TextBox,你會像這樣綁定: Fabrice 2013-04-29 06:05:25