Dynamic Binding - in code [SOLVED]

vsipen
Posts: 4
Joined: Tue Jun 07, 2016 1:03 pm

Dynamic Binding - in code [SOLVED]

Postby vsipen » Tue Jun 07, 2016 1:11 pm

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?
Last edited by vsipen on Thu Jun 09, 2016 11:06 am, edited 1 time in total.

JS-Support
Site Admin
Posts: 738
Joined: Tue Apr 08, 2014 3:42 pm

Re: Dynamic Binding - in code

Postby JS-Support » Wed Jun 08, 2016 6:25 am

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

vsipen
Posts: 4
Joined: Tue Jun 07, 2016 1:03 pm

Re: Dynamic Binding - in code

Postby vsipen » Thu Jun 09, 2016 11:05 am

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
}

vsipen
Posts: 4
Joined: Tue Jun 07, 2016 1:03 pm

Re: Dynamic Binding - in code

Postby vsipen » Mon Jun 13, 2016 12:01 pm

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.

JS-Support
Site Admin
Posts: 738
Joined: Tue Apr 08, 2014 3:42 pm

Re: Dynamic Binding - in code

Postby JS-Support » Wed Jun 15, 2016 6:55 am

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

vsipen
Posts: 4
Joined: Tue Jun 07, 2016 1:03 pm

Re: Dynamic Binding - in code [SOLVED]

Postby vsipen » Thu Jun 16, 2016 10:08 am

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


Return to “General Discussion and Other”

Who is online

Users browsing this forum: No registered users and 1 guest

 

 

cron