ListView 내에서 체크 상자에 대해 양방향 바인딩을 만들고 싶습니다. 뷰 모델 클래스에서 CheckBox 양방향 바인딩이 작동하지 않습니다.
public class Product
{
public bool IsSelected { get; set; }
public string Name { get; set; }
}
가 나는 제품의 관찰 모음이 : 이것은 내 제품 클래스입니다 내가 ListView에 그리드를
private ObservableCollection<Product> _productList;
public ObservableCollection<Product> ProductList
{
get
{
return _productList;
}
set
{
_productList = value;
}
}
public MainViewModel()
{
ProductList = new ObservableCollection<Product>
{
new Product {IsSelected = false, Name = "Not selected"},
new Product {IsSelected = true, Name = "Selected"},
new Product {IsSelected = true, Name = "Selected"}
};
}
}
그리고 마지막을 나의 제품 목록 바인딩 :
<Grid>
<ListView Height="120" HorizontalAlignment="Left"
VerticalAlignment="Top"
SelectionMode="Multiple"
ItemsSource="{Binding ProductList}" >
<ListView.View>
<GridView>
<GridViewColumn Width="40">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="120" Header="Product Name" DisplayMemberBinding="{Binding Path=Name}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
나는 체크 박스를 체크하거나 체크하지 않을 때 결코 setter의 라인에 도착하지 않는이 어플리케이션을 디버깅한다. 이 코드의 잘못된 점은 무엇입니까? 미리 감사드립니다.
http://stackoverflow.com/a/504936/440030 –