How to add "x:name" attribute to a GridviewColumn dynamically?

54 Views Asked by At

I have these codes:

For i = 0 To clmncount
  Dim GridView2 As New GridViewColumn
  GridView2.SetValue(NameProperty, "Grclnm" & i)
  datatemple1 = New DataTemplate
  Dim a as New FrameworkElementFactory(GetType(TextBox))
  a.SetValue(Grid.ColumnProperty, 0)
  Dim actualB As New Binding("ActualWidth")
  actualB.ElementName = GridView2.GetValue(NameProperty)
  Dim st As New Style(GetType(TextBox))
  Dim stt As New Setter(TextBox.WidthProperty, actualB)
  st.Setters.Add(stt)
  a.SetValue(TextBox.StyleProperty, st)
  datatemple1.VisualTree = a
  GridView2.Header = "Employee No." & x
  GridView2.Width = 99
  GridView2.CellTemplate = datatemple1
  UGridview1.Columns.Add(GridView2)
Next

By these codes i am trying to make similar codes of these XAML:

<Style>
  <Setter Property = "Width" Value ="{Binding ElementName=Grclnm0,Path=ActualWidth}"/>
</Style>

But this

 GridView2.SetValue(NameProperty, "Grclnm" & i)

VB.Net is not working. How can i set the "x:name" value of GridviewColumn by dynamically? I couldn't find the solution.

1

There are 1 best solutions below

0
On

You could use the BindingOperations.SetBinding method and set the Source property of the binding to Grclnm0:

BindingOperations.SetBinding(GridView2, GridViewColumn.WidthProperty, 
    New Customer("ActualWidth") With {.Source = Grclnm0})