There is a database loaded into the table.
public ObservableCollection<Items> TableData { get; private set; } public class Items { public ObservableCollection<object> ItemList { get; set; } = new ObservableCollection<object>(); } I don’t know the number of columns and lines. The type of columns is unloaded when the program is started. I want to visualize it in a datagrid. If you use the standard types, it works.
<UserControl x:Class="TMS.TableViewerUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:TMS" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="40"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> <DataGrid x:Name="Data" Grid.Row="1" AutoGenerateColumns="False"> </DataGrid> </Grid> foreach (KeyValuePair<string, ColumnInfo> column in DataBaseInfo.ColumnInfo) { Data.Columns.Add(new DataGridTextColumn() { Header = column.Key, Binding = new Binding() { Path = new PropertyPath(String.Format("ItemList[{0}]", columnNumber++)) } }); } But their functionality is not enough. I try to do through DataGridTemplateColumn
public partial class TableDataTemplate : DataGridTemplateColumn { public TableDataTemplate() { InitializeComponent(); } } <DataGridTemplateColumn x:Class="TMS.TableDataTemplate" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:TMS" mc:Ignorable="d"> <DataGridTemplateColumn.CellTemplate> <DataTemplate x:Name="TamplateItem"> <Grid x:Name="Root" > <TextBox x:Name="ItemValue" TextWrapping="Wrap" Text="{Binding Path=???}"/> </Grid> </DataTemplate> </DataGridTemplateColumn.CellTemplate> foreach (KeyValuePair<string, ColumnInfo> column in DataBaseInfo.ColumnInfo) { Data.Columns.Add(new DataGridTemplateColumn() { Header = column.Key, }); } How can I change the settings of the created templates? Is it possible to somehow address by name (ItemValue) for example? I understand that now I am creating only a template. How to create an element on this template?