Wpf binding code

In the code, I am adding columns to the list successfully. But I want to add a binding to the column, and not add to the listview.

fist is the working code in xaml.

<GridViewColumn x:Name="colName" Header="Name" Width="130"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Values, Converter={StaticResource LoadProfileConverter},ConverterParameter=active_total}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> 

Code behind:

 GridViewColumn column = new GridViewColumn(); column.Header = "Header"; column.Width = 130; FrameworkElementFactory controlFactory = new FrameworkElementFactory(typeof(TextBlock)); var itemsBinding = new System.Windows.Data.Binding("Values") { Converter = new LoadProfileConverter(), ConverterParameter = "active_total", }; controlFactory.SetBinding(TextBox.TextProperty, itemsBinding); DataTemplate template = new DataTemplate(); template.VisualTree = controlFactory; column.CellTemplate = template; LoadProfileGrid.Columns.Add(column); 
+4
source share
2 answers
 var itemsbinding = new Binding("Values") { Converter = new LoadProfileConverter(), ConverterParameter = key }; controllerFactory.SetBinding(TextBox.TextProperty, itemsbinding); 

Create the correct binding using the code above.

Loading additional properties of a binding object that can help you.

+14
source
  GridViewColumn column = new GridViewColumn(); column.Header = key; column.Width = 130; FrameworkElementFactory controlFactory = new FrameworkElementFactory(typeof(TextBlock)); var itemsBinding = new System.Windows.Data.Binding("Values") { Converter = new LoadProfileConverter(), ConverterParameter = key }; column.DisplayMemberBinding = itemsBinding; LoadProfileGrid.Columns.Add(column); 
0
source

All Articles