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);
source share