Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe the reason why you are getting this error:</p> <pre><code>An object reference is required for the non-static field, method, or property 'Presentation.Print.PrintViewModel.ViewFullRecipeGrouping.get' </code></pre> <p>is because you're trying to access the <code>property</code> as if it is static. Without knowing too much about your ViewModel class, is the class static itself? If it's not, the way you are trying to access it won't work.. you will need to first instantiate the class, then access the property like so: (you may also need to set the data context)</p> <pre><code> private PrintViewModel _viewModel = new PrintViewModel(); private void Window_Loaded(object sender, RoutedEventArgs e) { this.DataContext = _viewModel; var datagrid = new DataGrid(); datagrid.ItemsSource = _viewModel.ViewFullRecipeGrouping; } </code></pre> <p>I would also like to ask, why are you programmatically creating the DataGrid? Why not define it via XAML and and use DataBinding for the ItemsSource.</p> <p>Also, I'd like to note that the point of Properties is for encapsulation. You are using a "getter" for a public member variable.. The member variable should actually be private:</p> <pre><code>private List&lt;ViewFullRecipe&gt; _viewFullRecipeGrouping = new List&lt;ViewFullRecipe&gt;(); public List&lt;ViewFullRecipe&gt; ViewFullRecipeGrouping { get { return _viewFullRecipeGrouping; } set { Set(ViewFullRecipeGroupingPropertyName, ref _viewFullRecipeGrouping, value, true); } } </code></pre> <p><strong>Edit:</strong> Okay, since you are using a "factory" to get what looks like a singelton instance of the ViewModel, update the code to:</p> <pre><code> private ViewModelLocator _locator = new ViewModelLocator(); private void Window_Loaded(object sender, RoutedEventArgs e) { var viewModel = _locator.Print; // your ViewModel instance var datagrid = new DataGrid(); datagrid.ItemsSource = viewModel.ViewFullRecipeGrouping; } </code></pre> <p>or try setting the DataBinding of the GridView</p> <pre><code> private ViewModelLocator _locator = new ViewModelLocator(); private void Window_Loaded(object sender, RoutedEventArgs e) { var viewModel = _locator.Print; // your ViewModel instance this.DataContext = viewModel; var datagrid = new DataGrid(); var binding = new Binding("ViewFullRecipeGrouping"); BindingOperations.SetBinding(datagrid, DataGrid.ItemsSource, binding); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload