2012-03-21 3 views
2

ListBoxItem의 콘텐츠의 IsEnabled 속성에 따라 ListBox 항목을 사용하지 않도록 설정하려고합니다. 이 코드에서와 같이 버튼 1에는 IsEnabled = False가 있지만 목록 상자 항목을 선택할 수 있습니다. 내용 IsEnabled 속성이 false 인 경우 선택을 비활성화하려고합니다. 아이템 컨텐트와 IsEnabled 속성을 어떻게 검색해야 하는가?ListBoxItem에서 트리거에 대해 자식 컨트롤의 IsEnabled 속성을 찾는 방법

<Grid> 
     <ListBox> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <DataTemplate.Triggers> 
        <Trigger Property="IsEnabled" Value="False"> 
        <Setter Property="IsEnabled" Value="False"/> 
        </Trigger> 
       </DataTemplate.Triggers> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
     <ListBoxItem> 
      <Button IsEnabled="False">1</Button> 
     </ListBoxItem> 
     <ListBoxItem> 
      <Button>2</Button> 
     </ListBoxItem> 
     <ListBoxItem> 
      <Button>3</Button> 
     </ListBoxItem>   
     </ListBox> 
</Grid> 

답변

0

이유는 단지 대신 ListBoxItemIsEnabled를 설정하지? Button도 비활성화해야합니다.

하지만 그 말은 WPF와 함께 작업하는 경우, I '는 Button.IsEnabledRelativeSource 바인딩을 사용하여 ListBoxItem.IsEnabled에 결합하고, ListBoxItemIsEnabled 재산이 아니라 너무 Button

<Button IsEnabled="{Binding IsEnabled, 
    RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}" /> 

을 설정할 수 있습니다 MVVM 디자인 패턴을 살펴 보는 것이 좋습니다. WPF에 매우 적합하고 ListBoxItem.IsEnabledButton.IsEnabled을 모두 DataContext

+1

의 속성에 바인딩 할 수 있습니다. 그러나 이것은 내가 달성하기를 원하는 것이 아닙니다. 자식 컨트롤의 IsEnabled 속성을 가져 오려고합니다. MVVM을 사용하고 있지만 리소스 사전에있는 스타일로 트리거를 사용하고 싶습니다. – DronBoard

관련 문제