我尝试在 DataGrid 中绑定 CheckBox 但在设计器中我在悬停时得到DoImport
由于未知的数据上下文,无法解析符号“DoImport”
我的代码是
<Window x:Class="MyWindow">
<Grid>
<DataGrid x:Name="MyGrid" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Import"
Binding="{Binding Path=DoImport,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
public partial class MyWindow : Window, INotifyPropertyChanged {
public MyWindow(ObvervableCollection<Part> parts) {
_parts = parts;
MyGrid.DataContext = _parts;
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string name) {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
private ObservableCollection<Part> _parts;
public ObservableCollection<Part> Parts {
get { return _parts; }
set
{
_parts = value;
OnPropertyChanged("Parts");
}
}
}
_parts
是填充 DataGrid 的项的集合。Part
课程是:
public class Part {
public bool DoImport { get; set; }
}