【问题标题】:How to set SelectItem Foreground in LongListSelector如何在 LongListSelector 中设置 SelectItem 前景
【发布时间】:2012-03-27 02:20:32
【问题描述】:

我想在 LongListSelector 中设置具有差异颜色的 SelectItem Foreground 这是我的 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。

【问题讨论】:

    标签: windows-phone-7 silverlight-toolkit longlistselector


    【解决方案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.xaml 中的 ListBoxItem 样式匹配的样式,除了用于不同的选定项目视觉状态颜色。

    【讨论】:

      猜你喜欢
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-09
      • 2015-03-26
      • 1970-01-01
      • 2011-03-06
      相关资源
      最近更新 更多