Simple Example

In the .xaml file

Add this to the start with the other xmlns lines:

    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    xmlns:prim="using:Microsoft.Toolkit.Uwp.UI.Controls.Primitives"

Add this where you want your DataGrid:


            <!-- DATA GRID -->
            <controls:DataGrid Canvas.Left="10" Canvas.Top="530" Width="780" Height="730" x:Name="DataGrid1"
                               ItemsSource="{x:Bind DataGridData1}"
                               AutoGenerateColumns="False" 
                               CanUserReorderColumns="False" CanUserResizeColumns="False"
                               CanUserSortColumns="False" SelectionMode="Single" >

                <controls:DataGrid.Columns>
                    <controls:DataGridTextColumn Header="Cat" Binding="{Binding Category}" Width="300" IsReadOnly="True" ></controls:DataGridTextColumn>
                    <controls:DataGridCheckBoxColumn Header="Chk" Binding="{Binding Value2}" Width="40" IsReadOnly="True" ></controls:DataGridCheckBoxColumn>
                    <controls:DataGridTextColumn Header="Value 1" Binding="{Binding Value1}" Width="200" IsReadOnly="True" ></controls:DataGridTextColumn>
                </controls:DataGrid.Columns>
            </controls:DataGrid>
In the .cs file
	//-------------------------------
	//----- CLASS FOR DATA GRID -----
	//-------------------------------
	public class DataGridData
	{
		public string Category { get; set; }
		public double Value1 { get; set; }
		public bool Value2 { get; set; }

		//----- CONSTRUCTOR -----
		public DataGridData (string Category, double Value1, bool Value2)
		{
			this.Category = Category;
			this.Value1 = Value1;
			this.Value2 = Value2;
		}
	}
	public List<DataGridData> DataGridData1;

In your function:

	//----- SET DATAGRID DATA -----
	DataGridData1 = new List<DataGridData>();
	DataGridData1.Add(new DataGridData("Cat0", 1000, true));
	DataGridData1.Add(new DataGridData("Cat1", 1001, false));

	//Reload the datagrid
	DataGrid1.ItemsSource = DataGridData1;
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *