在Windows Phone 8.1中,如何在选择ListView项时更改它的样式

时间:2015-05-05 18:08:53

标签: windows-phone-8.1 winrt-xaml

我创建了一个Win Phone 8.1项目,显示了一个ListView,其中每个项目都显示在一个简单的TextBlock中。就像在Store Store中使用Hub App模板创建新项目时的第一个HubSection一样 - > Windows Phone应用程序。

<HubSection x:Uid="HubSection1" Header="My Data">
            <DataTemplate>
                <ListView
                    ItemsSource="{Binding CollectionOfData}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,0,0,16">
                                <TextBlock Text="{Binding MyDataProperty}" Style="{ThemeResource ListViewItemTextBlockStyle}" />
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </DataTemplate>
        </HubSection>

现在我试图找出如何更改所选ListViewItem TextBlock中文本的样式。这就是我希望所选项目的文本设置为粗体。我想我之前使用触发器做过类似的事情。

2 个答案:

答案 0 :(得分:0)

我认为您可以使用Microsoft.Xaml.Interactivity和HTML标记来实现此目的。查看此博客文章:Displaying HTML content in a TextBlock。我有一个固定的绑定和样式代码,告诉我你是否需要它。

答案 1 :(得分:0)

您可以编辑ItemStyleContainer,然后找到VisualState x:Name="Selected"并更改为:

<VisualState x:Name="Selected">
    <Storyboard>
        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="CheckGlyph"/>
        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedCheckMark"/>
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="contentPresenter">
            <DiscreteObjectKeyFrame KeyTime="0">
                <DiscreteObjectKeyFrame.Value>
                    <SolidColorBrush Color="Red"/>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>
</VisualState>

您可以将<SolidColorBrush Color="Red"/>从红色更改为您想要的颜色

相关问题