2012-09-12 1 views
2

내 콤보 상자는 상태 목록에 바인딩됩니다. 상태에는 실제로 참여할 때 콤보 항목의 전경색이 빨간색이어야하는 열이 있습니다. 이것은 잘 작동합니다. 그러나 전경색이 빨간색 인 콤보 상자 항목을 선택하면 해당 전경색이 손실되어 검정색으로 설정됩니다. 누군가 제가 잘못하고있는 것을 지적하도록 도와 줄 수 있습니까?WPF 콤보 상자 선택 항목 색을 콤보 상자 색으로 설정합니다.

<ComboBox Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBoxItem}},Path=Foreground}" 
      DisplayMemberPath="StateName" 
      ItemsSource="{Binding States}" 
      SelectedValue="{Binding Model.StateID}" SelectedValuePath="StateID" > 
    <ComboBox.ItemContainerStyle> 
     <Style TargetType="{x:Type ComboBoxItem}"> 
      <Setter Property="Foreground" Value="{Binding DoesNotParticipate, Converter={StaticResource NonParticipatingConverter}}"/> 
     </Style> 
    </ComboBox.ItemContainerStyle> 
</ComboBox> 

답변

1

하면 당신은 시각적 트리에서 ComboBotItem 입력 조상을 찾고있는 당신의 ComboBoxeForeground 소품 설정 바인딩,하지만 당신이 필요로하는 항목은 ComboBox의 후손이다. 특히 ComboBoxes SelectedItem. 당신이 결합하기 때문에

편집

모델링 할 수있는 항목은 ComboBox.SelectedItems 유형이 모델 유형을 객체 것이다 오브젝트. 즉, Foreground 속성이없는 것 같습니다. DoesNotParticipate 그래서 대신 Trigger 사용 Converter를 사용하지 않는 부울 소품 것을 나에게 보인다 : 보이지 않는다

<ComboBox Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBoxItem}},Path=Foreground}" 
     DisplayMemberPath="StateName" 
     ItemsSource="{Binding States}" 
     SelectedValue="{Binding Model.StateID}" SelectedValuePath="StateID" > 
<ComboBox.Style> 
    <Style TargetType="ComboBox"> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.DoesNotParticipate}" Value="True"> 
         <Setter Property="Foreground" Value="Red"/> 
        </DataTrigger 
     </Style.Triggers> 
    </Style> 
</ComboBox.Style> 
<ComboBox.ItemContainerStyle> 
    <Style TargetType="{x:Type ComboBoxItem}"> 
     <Style.Triggers> 
     <DataTrigger Property={Binding DoesNotParticipate} Value="True"> 
      <Setter Property="Foreground" Value="Red"/> 
     </DataTrigger> 
     </Style.Triggers> 
    </Style> 
</ComboBox.ItemContainerStyle> 
</ComboBox> 
+0

중 하나가 작동하는

나는 다음 당신에게 추천합니다. –