2015-05-05 112 views
0

我創建了一個顯示ListView的項目,其中每個項目都顯示在一個簡單的TextBlock中。就像在第一個HubSection中,當您使用Store Apps - > Windows Phone Apps下的Hub App模板創建新項目時一樣。在Windows Phone 8.1中,如何在更改ListView項目的樣式時更改

<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的文本的樣式。這是我想要爲選定的項目設置爲粗體文本。我想我以前用觸發器做過類似的事情。

回答

0

我認爲你可以用Microsoft.Xaml.Interactivity和HTML標籤來實現這一點。檢查這篇博客文章:Displaying HTML content in a TextBlock。我有一個固定的綁定和樣式代碼,告訴我你是否需要它。

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"/>你的願望顏色

+0

這並不工作 – garenyondem

相關問題