DataGridTemplateColumns, AutoGenerateColumns=true and binding to a DataTable

前端 未结 3 2030
孤独总比滥情好
孤独总比滥情好 2021-01-21 03:12

I\'m struggling with a confluence of problems.

  1. I have a dynamic data set which I manually assemble into a DataTable.
  2. I have to auto generate the columns a
3条回答
  •  误落风尘
    2021-01-21 03:58

    Dusan's answer set me on the right track. Because I don't know the column names until runtime, I have to create the data template at runtime too. It's actually not difficult.

    private DataTemplate GetDataTemplate(string columnName)
    {
        string xaml = "";
    
        var sr = new MemoryStream(Encoding.ASCII.GetBytes(xaml));
        var pc = new ParserContext();
        pc.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
        pc.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
        var datatemplate = (DataTemplate)XamlReader.Load(sr, pc);
    
        return datatemplate;
    }
    

提交回复
热议问题