4

In code i add columns to listview successfuly. But i want add binding to column than add to listview.

fist is 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);
cdbitesky
  • 1,390
  • 1
  • 13
  • 30
Armen Khachatryan
  • 831
  • 3
  • 22
  • 37

2 Answers2

15
var itemsbinding = new Binding("Values")
            {
                Converter = new LoadProfileConverter(),
                ConverterParameter = key
            };

        controllerFactory.SetBinding(TextBox.TextProperty, itemsbinding);

Create a proper binding using the code above.

Loads of extra properties on the binding object that can assist you.

KyorCode
  • 1,477
  • 1
  • 22
  • 32
0
 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);
Armen Khachatryan
  • 831
  • 3
  • 22
  • 37