3

I try to bind a CheckBox in a DataGrid but in the designer I get while hovering over DoImport

cannot resolve symbol 'DoImport' due to unknown datacontext

My code is

<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"); } } } 

The _parts is a collection of items that fill the DataGrid. The Part class is:

public class Part { public bool DoImport { get; set; } } 
4
  • What is CompareWindow(ObvervableCollection<Part> parts)? Shall this be the constructor for MyWindow? Commented Jun 5, 2013 at 10:18
  • Yes, I corrected that. Commented Jun 5, 2013 at 10:24
  • @Egi: Done. Nothing special in that class. Commented Jun 5, 2013 at 11:30
  • Check out stackoverflow.com/questions/25549826/… Commented Sep 14, 2014 at 17:59

1 Answer 1

1

The designer cannot supply a ObvervableCollection<Part> instance to the MyWindow constructor, because it does not know how. so your constructor should never be called in the designer. that is why the designer "cannot resolve symbol 'DoImport' due to unknown datacontext". the designer in visual studio expects a parameter-less default constructor in order to work properly.

maybe you should check that out: http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/sample-data-in-the-wpf-and-silverlight-designer.aspx or better yet ... let blend create design sample data for you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.