Windows phone 7 列表框:“;省略号;选择后,文本块的颜色错误

Windows phone 7 列表框:“;省略号;选择后,文本块的颜色错误,windows-phone-7,xaml,Windows Phone 7,Xaml,我有一个列表框,它的ItemTemplate中有一些文本块。 此文本块定义为此文本块 <TextBlock Grid.Column="1" Grid.Row="0" Text="{BindingGasStationName}" FontSize="20" FontFamily="Segoe WP SemiLight" Margin="0,0,0,0" Padding="0" MinHeight="27" TextTrimming="WordEllipsis"/>

我有一个列表框,它的ItemTemplate中有一些文本块。 此文本块定义为此文本块

<TextBlock Grid.Column="1" Grid.Row="0" Text="{BindingGasStationName}" 
    FontSize="20" FontFamily="Segoe WP SemiLight" Margin="0,0,0,0" Padding="0"
    MinHeight="27" TextTrimming="WordEllipsis"/>

省略号按预期工作。 问题是,当用户选择一个项目时,文本的颜色(以及“…”)将更改为当前系统高亮显示颜色。这就是我想要的。 但是,当用户更改选择时,“…”将保留突出显示的颜色,文本将再次变回白色

这是一个已知的bug还是我做错了什么

更新

当用户再次选择带有无效彩色省略号的项目时,在再次设置突出显示颜色之前,它会变白一段时间…

我刚刚重现了我的错误,对我来说肯定像一个WP bug

解决方法是使用
VisualStates
手动执行
ListBoxItem
样式设置。我在这里提供了一个示例,说明如何使用正确的强调色设置
ListBoxItem
的样式以完全高亮显示(包括省略号)。您可以设置
ListBoxItem
ControlTemplate
,并为未选定状态和选定状态指定前景色。希望这有帮助

<ListBox Name="TheListBox">
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="MouseOver"/>

                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="SelectionStates">
                                        <VisualState x:Name="Unselected">
                                            <Storyboard>
                                                <ColorAnimation Duration="0" To="{StaticResource PhoneForegroundColor}" Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)" Storyboard.TargetName="ContentContainer" d:IsOptimized="True"/>
                                                <ColorAnimation Duration="0" To="{StaticResource PhoneForegroundColor}" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="ContentContainer" d:IsOptimized="True"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Selected">
                                            <Storyboard>
                                                <ColorAnimation Duration="0" To="{TemplateBinding Foreground}" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="ContentContainer" d:IsOptimized="True"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="SelectedUnfocused">
                                            <Storyboard>
                                                <ColorAnimation Duration="0" To="{TemplateBinding Foreground}" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="ContentContainer" d:IsOptimized="True"/>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="#FF1BA1E2" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="Black" BorderBrush="Black"/>
                            </Border>
                        </ControlTemplate>

                    </Setter.Value>
                </Setter>
            </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding}" 
FontSize="20" FontFamily="Segoe WP SemiLight" Margin="0,0,0,0" Padding="0"
MinHeight="27" TextTrimming="WordEllipsis"/>

            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>


感谢您提供此代码!因为省略号在初始加载时总是以强调色显示,所以我更改了一些细节:1)删除行[];2)在“未选中”部分使用[To=“{TemplateBinding Foreground}]”;3)在“选中”部分使用[To=“{StaticResource PhoneAccentColor}”。顺便说一句,我以前也尝试过类似的方法,但是本文中的代码暂挂:它不起作用。。。可能问题在于本文使用的[Storyboard][ObjectAnimationUsingKeyFrames]可能与默认实现相同=)