Page 1 of 1

Dynamic Binding - in code [SOLVED]

Posted: Tue Jun 07, 2016 1:11 pm
by vsipen
I have a In-browser WPF app that does significant amount of Data Binding in code - different columns are added to a DataGrid and dynamically bound to data sources. I tried beta 8 - I could add a column to a XAML defined DataGrid, but I could not bind and manipulate its value. Is there anything now or in your future plans to allow dynamic binding of DataGrid in code?

Re: Dynamic Binding - in code

Posted: Wed Jun 08, 2016 6:25 am
by JS-Support @Userware
Hi,

Welcome to the forums.

This is supposed to work already. Can you please post some minimal source code to reproduce the issue?

Thanks,
Regards,
JS-Support

Re: Dynamic Binding - in code

Posted: Thu Jun 09, 2016 11:05 am
by vsipen
I changed only a few lines - between Debug Start and End - of your Showcase - the "textColumn" shows up in the "DataGrid1", but without any values.

namespace CSHTML5Showcase
{
public sealed partial class Page1_Controls : Page
{
public Page1_Controls()
{
this.InitializeComponent();

// Populate the ComboBox and ListBox with the list of planets:
ComboBox1.ItemsSource = Planet.GetListOfPlanets();
ListBox1.ItemsSource = Planet.GetListOfPlanets();

// Populate the data grids with the list of planets
DataGrid1.ItemsSource = Planet.GetListOfPlanets();
DataGrid2.ItemsSource = Planet.GetListOfPlanets();

//Debug start
Binding binding = new Binding("Name");
binding.Source = Planet.GetListOfPlanets();
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Test Header";
textColumn.Binding = binding;

DataGrid1.Columns.Add(textColumn);
//End Debug
}

Re: Dynamic Binding - in code

Posted: Mon Jun 13, 2016 12:01 pm
by vsipen
JS-Support,

Did you have a chance to confirm the binding problem I mentioned or it just takes that long to do this?
The availability of Dynamic Binding in Code would define mine interest in this product and I am eagerly waiting to see your answer.

Re: Dynamic Binding - in code

Posted: Wed Jun 15, 2016 6:55 am
by JS-Support @Userware
Hi,

OK, we looked into the issue.

Please use "SetBinding" instead of "Binding", and do not set the "Source" of the binding because it will automatically be set to each grid row.

Here is the code that works fine:

Code: Select all

//Debug start
Binding binding = new Binding("Name");
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "Test Header";
textColumn.SetBinding(DataGridBoundColumn.BindingProperty, binding);

DataGrid1.Columns.Add(textColumn);
//End Debug


Please note that "DataGrid1" has AutoGenerateColums="True". In this case, the manually added column will appear as the first column of the DataGrid.

Let us know if you have any other questions. We are here to help.

Regards,
JS-Suppot

Re: Dynamic Binding - in code [SOLVED]

Posted: Thu Jun 16, 2016 10:08 am
by vsipen
Thanks a lot - this worked.

Is there any way to add other controls to the DataGrid programmatically and dynamically bind them? My system creates and dynamically binds pretty much all DataGrid associated controls. I was looking for a DataGridComboBoxColumn and could not find one ?

Vova