如何在wp8中设置ListPicker的完整头模板
本文关键字:ListPicker wp8 设置 | 更新日期: 2023-09-27 17:57:47
我正在使用下面的代码为listpicker附加完整的头模板,但我遇到了异常。
<toolkit:ListPicker x:Name="lspTranslationLang" ExpansionMode="FullScreenOnly"
SelectedItem="{Binding Name, Mode=TwoWay}" SelectionChanged="lspTranslationLang_SelectionChanged">
<toolkit:ListPicker.FullModeHeader>
<DataTemplate>
<TextBlock FontWeight="Bold" Foreground="Black" Text="Select Translation"></TextBlock>
</DataTemplate>
</toolkit:ListPicker.FullModeHeader>
<toolkit:ListPicker.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontWeight="Bold" Foreground="Black" Text="Select Translation"></TextBlock>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.HeaderTemplate>
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontSize="30" Text="{Binding Language}" />
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<Grid Margin="0" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Margin="10,0,0,0" Width="30" Height="30" Grid.Column="0" Source="{Binding ImagePath}" ></Image>
<TextBlock Grid.Row="0" Padding="10,0,10,0" Grid.Column="1" Foreground="Black" Text="{Binding Language}" FontSize="30"/>
<TextBlock Grid.Row="1" Padding="10,0,10,0" Grid.Column="1" Foreground="Black" Text="{Binding Description}" FontSize="30"/>
<Line X1="0" X2="480" Y1="0" Y2="0" Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Bottom" StrokeThickness="1" Stroke="LightGray" />
</Grid>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
例外情况:
{System.InvalidCastException: Unable to cast object of type 'System.Windows.DataTemplate' to type 'System.String'.
如果我删除FullHeaderTemplate
,也没有例外。
如何修改listpicker的完整页眉模板?
谢谢!
我认为FullModeHeader
只是标题。您实际想要的是FullModeItemTemplate
。参见以下示例:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Resources>
<DataTemplate x:Name="PickerFullModeItemTemplate">
<TextBlock Margin="0, 10, 0, 0" Style="{StaticResource PhoneTextGroupHeaderStyle}" Text="{Binding ItemText}"></TextBlock>
</DataTemplate>
</Grid.Resources>
<ScrollViewer>
<Grid>
<TextBlock Style="{StaticResource PhoneTextGroupHeaderStyle}" TextWrapping="Wrap">Choose an option to group the list of task</TextBlock>
<TextBlock Style="{StaticResource PhoneTextGroupHeaderStyle}" Foreground="Aqua" Margin="12,100,0,0" Name="OptionText" Text="Current Option:"></TextBlock>
<toolkit:ListPicker ExpansionMode="FullScreenOnly" FullModeHeader="Choose an option" SelectionMode="Single" FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}" Name="GroupingPicker" Header="Choose grouping option" Margin="12,150,12,0"></toolkit:ListPicker>
</Grid>
</ScrollViewer>
</Grid>