Hey. There is a dataGridview -

<DataGrid x:Name="DataGridXAML" HorizontalAlignment="Left" Height="441" Margin="10,89,0,0" VerticalAlignment="Top" Width="1044"> <DataGrid.Columns> <DataGridTextColumn Header="ID сотрудника"/> <DataGridTextColumn Header="Имя" Width="100"/> <DataGridTextColumn Header="Фамилия" Width="120"/> <DataGridTextColumn Header="Отчество" Width="*"/> </DataGrid.Columns> </DataGrid> 

How can the number of columns, their name and other parameters be changed through the code?

From another xaml page.

  • You can find out what you want to get? - user227049
  • You can access controls by name, in your case, this is DataGridXAML - user227049
  • Refer to the element of another xaml page. - xomem
  • @xomem, read this: ru.stackoverflow.com/a/764737/218063 - Andrey NOP
  • Read it. Made. Works. Thank. - xomem

1 answer 1

What's the problem? For example:

 DataGridXAML.Columns.Add( new DataGridTextColumn() { Header="Дед Мороз", Width="200" }); 

To change:

 DataGridXAML.Columns[0].Header="Снегурочка"; 

Documentation: https://msdn.microsoft.com/ru-ru/library/system.windows.controls.datagrid.columns(v=vs.110).aspx

If you need access from another page, make this page accessible to another page in any way, and get access through yourPage.DataGridXAML.Columns...

  • I forgot to add that I need to change the same element from another XAML page. How to access another page? - xomem
  • And how to change the data? Do not add. - xomem
  • @xomem: Get the object of another page, take the DataGridXAML from it, then just the same. - VladD
  • @xomem: To change, you just need DataGridXAML.Columns[0].Header="Снегурочка" - VladD
  • Thank. And there is something like DataGridXAML.Columns [Where name == name ]. Header = "Snow Maiden". To add an identifier to each column and look for it already? - xomem