我需要为我的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>
感谢您的帮助!
答案 0 :(得分: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中绑定属性:
<ListBox ItemTemplate="{StaticResource MyItemTemplate}"/>