2011-08-08 6 views
1
나는 약간의 색상 목록 상자에서 선택한 항목의 배경을 변경하려면, 그래서 난 스타일 템플릿의 선택 상태를 변경하고

:목록 상자 선택 상태 사용자 정의

<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem"> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="BorderThickness" Value="0"/> 
    <Setter Property="BorderBrush" Value="Transparent"/> 
    <Setter Property="Padding" Value="0"/> 
    <Setter Property="HorizontalContentAlignment" Value="Left"/> 
    <Setter Property="VerticalContentAlignment" Value="Top"/> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="ListBoxItem"> 
     <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"> 
      <VisualStateManager.VisualStateGroups> 
      <VisualStateGroup x:Name="CommonStates"> 
       <VisualState x:Name="Normal"/> 
       <VisualState x:Name="MouseOver"/> 
       <VisualState x:Name="Disabled"> 
       <Storyboard> 
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot"> 
        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/> 
        </ObjectAnimationUsingKeyFrames> 
        <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/> 
       </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
      <VisualStateGroup x:Name="SelectionStates"> 
       <VisualState x:Name="Unselected"/> 
       <VisualState x:Name="Selected"> 
       <Storyboard> 
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" Storyboard.TargetProperty="Foreground" Duration="0"> 
        <DiscreteObjectKeyFrame KeyTime="0"> 
         <DiscreteObjectKeyFrame.Value> 
         <SolidColorBrush Color="White"/> 
         </DiscreteObjectKeyFrame.Value> 
        </DiscreteObjectKeyFrame> 
        </ObjectAnimationUsingKeyFrames> 
        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="Background" Duration="0"> 
        <DiscreteObjectKeyFrame KeyTime="0"> 
         <DiscreteObjectKeyFrame.Value> 
         <SolidColorBrush Color="YellowGreen"/> 
         </DiscreteObjectKeyFrame.Value> 
        </DiscreteObjectKeyFrame> 
        </ObjectAnimationUsingKeyFrames> 
       </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
      </VisualStateManager.VisualStateGroups> 
      <StackPanel x:Name="border" Orientation="Horizontal"> 
      <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
      </StackPanel> 
     </Border> 
     </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
</Style> 

을하지만, 내가이 템플릿을 추가 할 때 목록 상자에, 그것은 비어있는 것을로드합니다. 또한, 나는 다음과 같은 ItemTemplate을에 목록 상자의 항목을 결합하고있다 : 당신은 ListBoxItem의 템플릿을 변경해야

<DataTemplate x:Key="FlightsTemplate"> 
    <StackPanel Orientation="Horizontal" Margin="3" Background="#FF171717" Height="35"> 
    <TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="60" Text="{Binding Time}"/> 
    <TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="80" Text="{Binding Flight}"/> 
    <TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="150" Text="{Binding City}"/> 
    <TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="90" Text="{Binding Status}"/> 
    <TextBlock FontSize="19" Margin="1,0,0,0" TextAlignment="Center" Width="70" Text="{Binding Expected_Time}"/> 
    </StackPanel> 
</DataTemplate> 

답변

0

. 자세한 내용은 여기를 참조하십시오. http://forums.silverlight.net/post/64044.aspx

+0

죄송합니다.이 링크는 도움이되지 않았습니다. 그러나 http://www.windowsphonegeek.com/tips/How-to-customize-the-WP7-ListBox-Selected-Item--Part2-Visual-States : 나는 목록 상자를 사용자 지정하기 위해 다음의 예를 위의 질문에서 말했듯이 목록 상자를이 스타일에 바인딩하면 더 이상 항목이 표시되지 않습니다. – Ameen