我希望在LongListSelector中使用diff颜色设置SelectItem前景 这是我的xaml:
<toolkit:LongListSelector x:Name="locations" Background="Transparent" Margin="0"
GroupViewOpened="LongListSelector_GroupViewOpened"
GroupViewClosing="LongListSelector_GroupViewClosing"
SelectionChanged="locations_SelectionChanged">
<toolkit:LongListSelector.GroupItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</toolkit:LongListSelector.GroupItemsPanel>
<toolkit:LongListSelector.GroupItemTemplate>
<DataTemplate>
<Border Background="{Binding Converter={StaticResource GroupBackground}}"
Width="99" Height="99" Margin="6" IsHitTestVisible="{Binding HasItems}">
<TextBlock Text="{Binding Key}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"
FontSize="48"
Margin="8,0,0,0"
Foreground="{Binding Converter={StaticResource GroupForeground}}"
VerticalAlignment="Bottom"/>
<Border.Projection>
<PlaneProjection RotationX="-60"/>
</Border.Projection>
</Border>
</DataTemplate>
</toolkit:LongListSelector.GroupItemTemplate>
<toolkit:LongListSelector.GroupHeaderTemplate>
<DataTemplate>
<Border Background="Transparent" Margin="12,8,0,8">
<Border Background="{StaticResource HighlightBrush}"
Padding="8,0,0,0" Width="62" Height="62"
HorizontalAlignment="Left">
<TextBlock Text="{Binding Key}"
Foreground="#FFFFFF"
FontSize="48"
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"/>
</Border>
</Border>
</DataTemplate>
</toolkit:LongListSelector.GroupHeaderTemplate>
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="20,0">
<TextBlock Text="{Binding n}" Style="{StaticResource PhoneTextExtraLargeStyle}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"
Margin="12,5"/>
</StackPanel>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
</toolkit:LongListSelector>
没有“ItemContainerStyle”的LongListSelector,我不知道如何设置样式资源,就像普通的listboxitem一样。
答案 0 :(得分:1)
如果您编辑ItemTemplate以使用ContentControl而不是TextBlock,则所选项目将使用手机重音画笔(确保您没有为内容控件设置前景色):
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="20,0">
<ContentControl Text="{Binding n}" Style="{StaticResource PhoneTextExtraLargeStyle}"
FontFamily="{StaticResource PhoneFontFamilySemiBold}"
Margin="12,5"/>
</StackPanel>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
为了能够将其设置为自定义颜色,我最终覆盖了TemplatedListBoxItem的构造函数并设置了DefaultStyleKey:DefaultStyleKey = typeof(TemplatedListBoxItem);
然后我为TemplatedListBoxItem设置了一个与System.Windows中的ListBoxItem样式匹配的样式。 xaml除了不同的选定项目视觉状态颜色。