.NET
Microsoft Technologies based on the .NET software framework.
3,905 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to bind a column dynamically into the datagrid but datagrid does not allow this. I can only add static columns as I share below.
<DataGrid AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
RowHeaderWidth="0"
BorderBrush="{DynamicResource TertiaryBackgroundColor}"
Background="{DynamicResource PrimaryBackgroundColor}"
CanUserSortColumns="False"
ItemsSource="{Binding LPList}"
ScrollViewer.CanContentScroll="False"
IsReadOnly="True"
Margin="7 0 7 10"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
TextBlock.FontSize="12">
<DataGrid.Columns>
<DataGridTemplateColumn Header="{lex:Loc Key=MeterDate}">
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell">
</Style>
</DataGridTemplateColumn.CellStyle>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Path=MeterDate}" Margin="10 0 0 0"> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin=" 1 1 1 1" CornerRadius="5">
<TextBlock Text="{Binding}" FontFamily="Fonts/#Saira SemiBold" FontSize="12" Foreground="{DynamicResource PrimaryTextColor}" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGrid.Columns>
</DataGrid>