2012-04-16 2 views
1

나는 그것은 내 전체 ListBoxItem의 정확한 색상 색상 것테두리에 AlternationCount를 사용할 수없는 이유는 무엇입니까? 아래의 코드에서

<Style TargetType="{x:Type ListBoxItem}"> 

<Style TargetType="{x:Type Border}"> 

를 변경하는 경우. 그러나 나는 단지 내가이 시도

<ListBox x:Name="FilteredMessagesListBox" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch" SelectionMode="Extended" Background="Transparent" AlternationCount="2"> 
         <ListBox.Resources> 
          <Style TargetType="{x:Type Border}"> 
           <Style.Triggers> 
            <Trigger Property="ItemsControl.AlternationIndex" Value="0"> 
             <Setter Property="Background" Value="LightBlue"></Setter> 
            </Trigger> 
            <Trigger Property="ItemsControl.AlternationIndex" Value="1"> 
             <Setter Property="Background" Value="LightGreen"></Setter> 
            </Trigger> 
           </Style.Triggers> 
          </Style> 

         </ListBox.Resources> 

         <ListBox.ItemTemplate > 
          <DataTemplate> 
           <DockPanel Margin="0,0,0,3"> 
            <Button x:Name="AttachmentImageButton" Click="AttachmentImageButton_Click" DockPanel.Dock="Bottom" MaxWidth="200" MaxHeight="200" HorizontalContentAlignment="Center" Visibility="{Binding ElementName=AttachmentImageButton, Converter={StaticResource cImageAttachmentToVisible}}" > 
             <Image Source="{Binding Path=Attachment}" x:Name="AttachmentImage" /> 
            </Button> 
            <Button x:Name="AttachmentButton" Click="AttachmentButton_Click" DockPanel.Dock="Right" Visibility="{Binding ElementName=AttachmentButton, Converter={StaticResource cAttachmentToVisible}}" > 
             <Image Source="/MobilWPF;component/Resources/Images/PaperClip/PaperClip.jpg" Width="20" Height="20"/> 
            </Button> 

            <TextBlock Text="{Binding Converter={StaticResource cGetInstantMessageHeader}}" Width="120" TextWrapping="Wrap" HorizontalAlignment="Left" Background="Transparent" FontSize="10" DockPanel.Dock="Left"/> 

            <Border DockPanel.Dock="Left" HorizontalAlignment="Stretch" CornerRadius="5"> 
             <DockPanel> 
              <TextBlock Margin="5,0,0,0" Text="{Binding Path=Message}" TextWrapping="Wrap" DockPanel.Dock="Left" HorizontalAlignment="Left" Background="Transparent" FontSize="12"/> 
             </DockPanel> 
            </Border> 
           </DockPanel> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 

국경 배경을 공격 할 :

<Border DockPanel.Dock="Left" HorizontalAlignment="Stretch" CornerRadius="5"> 
             <Border.Triggers> 
              <DataTrigger Binding="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="0"> 
               <Setter Property="Background" Value="LightBlue"/> 
              </DataTrigger> 
              <DataTrigger Binding="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="1"> 
               <Setter Property="Background" Value="LightGreen"/> 
              </DataTrigger> 
             </Border.Triggers> 
    <DockPanel> 
              <TextBlock Margin="5,0,0,0" Text="{Binding Path=Message}" TextWrapping="Wrap" DockPanel.Dock="Left" HorizontalAlignment="Left" Background="Transparent" FontSize="12"/> 
             </DockPanel> 
            </Border> 

'ContentPresenter에'

답변

3

문제는 AlternationIndex을한다는 것이다 정적 멤버 종류에 'BackgroundProperty'을 찾을 수 없습니다 컨테이너 (이 경우에는 ListBoxItem)에 설정되며 일부 자식에는 설정되지 않습니다. 대신 부모 ListBoxItemAlternationIndex에 결합 DataTrigger의 사용하여이 문제를 해결할 수 :

<DataTrigger Binding="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" Value="0"> 
    <Setter Property="Background" Value="LightBlue"/> 
</DataTrigger> 
+0

감사 @Kent Boogaart이 문제를 해결하는 방법을 알고를 ... 온 정적 멤버 'BackgroundProperty'을 찾을 수 없습니다 'ContentPresenter'를 입력하십시오. – 0x4f3759df

관련 문제