2013-05-13 91 views
3

我有一個列表框,我想改變每一行的顏色。我測試了下面的代碼,但顏色不變。我錯過了什麼嗎?Listbox的改變顏色變化

<ListBox Height="250" BorderThickness="0" ItemsSource="{Binding Path=Results}" AlternationCount="2"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <Grid> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition></ColumnDefinition> 
           <ColumnDefinition></ColumnDefinition> 
           <ColumnDefinition></ColumnDefinition> 
          </Grid.ColumnDefinitions> 
          <TextBlock Grid.Column="0" FontFamily="Sagoe UI" FontSize="14" Text="{Binding FirstName, StringFormat='User: {0}'}" Padding="2" /> 
          <TextBlock Grid.Column="1" FontFamily="Sagoe UI" FontSize="14" Text="{Binding Company, StringFormat='Company: {0}'}" Padding="2" /> 
          <TextBlock Grid.Column="2" FontFamily="Sagoe UI" FontSize="14" Text="{Binding Dept, StringFormat='Department: {0}'}" Padding="2" >         
          </TextBlock> 
         </Grid>       
        </DataTemplate> 
       <ListBox.ItemTemplate> 

這裏是我的風格和resoruces結束標記和字典

 <Style TargetType="{x:Type ListBoxItem}"> 
      <Style.Triggers> 
       <Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
        <Setter Property="Background" Value="#19f39611"></Setter> 
       </Trigger> 
       <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
        <Setter Property="Background" Value="#19000000"></Setter> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ResourceDictionary> 
</UserControl.Resources> 
+1

剛剛測試了你的代碼。適用於我。 – cvraman 2013-05-13 16:28:39

+0

謝謝,我認爲它是正確的,不斷挖掘感謝! – KeyboardFriendly 2013-05-13 16:30:08

+0

再次感謝cvraman!我要去打我自己! – KeyboardFriendly 2013-05-13 17:15:42

回答

0

Forgot我用RadListBox,所以答案是改變開閉Control Tags

<telerik:RadListBox></telerik:RadListBox> 

Then

 <Style TargetType="{x:Type telerik:RadListBoxItem}"> 
      <Style.Triggers> 
       <Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
        <Setter Property="Background" Value="#19f39611"></Setter> 
       </Trigger> 
       <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
        <Setter Property="Background" Value="#19000000"></Setter> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ResourceDictionary> 
</UserControl.Resources>