Question
I have a DataGrid and would like to populate it with some test data, so I can see it in the designer while working on it. How do I do that?
What I already have
I've created two classes:
ProductList
using System.Collections.ObjectModel;
namespace Wpf.DataGrid
{
class ProductList
{
private ObservableCollection<Product> products = new ObservableCollection<SubSystem>();
public ProductList()
{
}
}
}
Product
namespace Wpf.DataGrid
{
public class Product
{
public string Name { get; set; }
public double Price { get; set; }
public Product(string name, double price)
{
Name = name;
Price = price;
}
}
}
What I already know
I already know how to instantiate a class with some properties from XAML:
<Window xmlns:local="clr-namespace:Wpf.InstantiateObjectFromXaml"
Title="MainWindow" Height="100" Width="300">
<Grid>
<Grid.Resources>
<local:MyData x:Key="myData" ButtonText="Value set from XAML" ColorName="LightBlue"/>
</Grid.Resources>
<Button Content="{Binding Source={StaticResource myData}, Path=ColorName}" Background="{Binding Source={StaticResource myData}, Path=ColorName}"/>
</Grid>
</Window>