2015-06-20 90 views
0

我目前正在創建一個充當任務跟蹤器的Windows 8.1商店應用程序。我目前的問題是我想更改列表視圖中列出的項目來表示它們的優先級。我想通過更改背景顏色來做到這一點。 IE:紅色=高,藍色=中等,綠色=低。如何更改基於ListBoxItem的ListBoxItem的背景顏色值

ListBoxItems本身遵循一個模板,下面是相關的文本字段我想基於x:Name = priorityBind的變化。

<StackPanel Orientation="Horizontal"> 
        <TextBlock Text="Priority: " Margin="10, 0, 10, 10" /> 
        <TextBlock x:Name="priorityBind" Text="{Binding Path=Priority}" Margin="10, 0, 10, 10"/> 
       </StackPanel> 
       <StackPanel Orientation="Horizontal"> 
        <TextBlock Text="Notes: " Margin="10, 0, 10, 10" /> 
        <TextBlock Text="{Binding Path=Notes}" Margin="10, 0, 10, 10"/> 
       </StackPanel> 
      </StackPanel> 
     </Grid> 
    </DataTemplate> 

我發現的所有例子似乎都是用過時版本的應用商店來完成的。設置觸發器似乎是建議的路線,但它似乎不再適用於更新後的版本。以下是我的ListView代碼片段。如果優先級文本框的值爲「低」,我如何修改它以使其僅將背景顏色更新爲綠色?

<ListView x:Name="eventsListView" Grid.Row="1" Grid.Column="1" 
        ItemTemplate="{StaticResource eventTemplate}"> 
      <ListView.Resources> 
       <Style TargetType="ListViewItem"> 
        <Style.Setters> 
         <Setter Property="BorderBrush" 
           Value="White" /> 
         <Setter Property="BorderThickness" 
           Value="5"/> 
         <Setter Property="Background" 
           Value="Green"/> 
        </Style.Setters> 
       </Style> 
      </ListView.Resources>  
     </ListView> 

回答

1

您可以指定哪些應該優先使用哪個tempalte使用ItemTemplateSelector

ItemTemplateSelector讓ListView控件呈現基於你給作爲parameter.This屬性不同的模板是最好的做法解決方案AFAIK。

相關問題