2011-03-03 5 views
0

첫째로 ListView 컨트롤 자체에 이것을 사용하고 있습니다 :각 GridViewColumn을 별도의 ObservableCollection에 바인딩하는 방법

ItemsSource="{Binding AllEffects}" 

그러면 GridViewColumn에 대한 개별 바인딩이 허용되지 않습니까?

게다가 AllEffects 나는 다른 2 ObservableCollection을 가지고있다. 다른 2 개의 GridViewColumn에 바인딩하고 싶다 :

public ObservableCollection<GPUSupportNode> GPUSupport { get; set; } 
public ObservableCollection<CPUSupportNode> CPUSupport { get; set; } 

public class CPUSupportNode 
{ 
    public bool IsSupported {get;set;} 
} 

GPUSupport/CPUSupportGPUSupport/CPUSupport을 연결하려고한다.

지금 당장 가지고 있습니다 :

<GridViewColumn 
    Width="Auto" 
    Header="GPU"> 
    <GridViewColumn.CellTemplate> 
     <DataTemplate> 
      <CheckBox 
       Margin="0" 
       HorizontalAlignment="Center" 
       IsChecked="{Binding GPUSupport, Mode=TwoWay}"/> 
     </DataTemplate> 
    </GridViewColumn.CellTemplate> 
</GridViewColumn> 

그러나 작동하지 않습니다. 이것이 가능한가?

답변

3

public class MyViewModel 
{ 

public ObservableCollection<GPUSupportNode> GPUSupport { get; set; } 
public ObservableCollection<CPUSupportNode> CPUSupport { get; set; } 
public ObservableCollection<TypeOfEffects> AllEffects{ get; set; } 

} 

같은 뷰 모델 클래스를 만드는 시도하고 MyViewModel의 인스턴스를 생성, 뷰 모델 말을하고 관찰 가능한 컬렉션으로 초기화 할 수 있습니다. 세트 ItemsSource

ItemsSource="{Binding ViewModel}" 

그러면 작동합니다.

<GridViewColumn 
    Width="Auto" 
    Header="GPU"> 
    <GridViewColumn.CellTemplate> 
     <DataTemplate> 
      <CheckBox 
       Margin="0" 
       HorizontalAlignment="Center" 
       IsChecked="{Binding GPUSupport, Mode=TwoWay}"/> 
     </DataTemplate> 
    </GridViewColumn.CellTemplate> 
</GridViewColumn> 
+0

감사합니다. 모든 ObservableCollections를 결합하려고하는 해킹처럼 보입니다. –

+0

MVVM은 WPF에서 Databinding Scenerios를 활성화하고 모델에서 뷰 코드를 분리하기위한 표준 패턴입니다. GUI를 사용하지 않고도 GUI까지 모든 방법을 쉽게 테스트 할 수 있습니다. 다음은 MVVM에 대한 블로그입니다. http://houseofbilz.com/archives/2009/05/22/adventures-in-mvvm-model-view-viewmodel/ –

관련 문제