I have a datagrid with rows begin added programatically, and my datagrid in xaml has 5 columns, and each column style is as shown here:
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" Header="Status"
FontFamily="Arial" Foreground="Gray" FontWeight="Normal"
MinWidth="250" Binding="{Binding Path=Date}" >
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<fa:ImageAwesome Icon="Sort" Height="10" Name="Search" Margin="10,15,25,0" HorizontalAlignment="Center" />
<!--<TextBlock FontFamily="FontAwesome" FontSize="16" Text="" />-->
<TextBlock Text="Date" Margin="0,-30,0,0" />
</StackPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.Margin" Value="0,8,0,0"></Setter>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Background" Value="#dec15a" />
<Setter Property="Height" Value="50" />
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#d5b024" />
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
</DataGrid.Columns>
How can I add a font awesome success icon next to the text like below when the rows is adding from code behind
Date | File| Status
03/14/2025|.pdf | Success (here the FontAwesome success icon should be shown)
Code-behind code is:
dgrd_ListFiles.Items.Add(new Item() { Date =
System.DateTime.Now.ToString("MM/dd /yyyy"), File=".pdf", Status = "Success" });
I have a datagrid with rows begin added programatically, and my datagrid in xaml has 5 columns, and each column style is as shown here:
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" Header="Status"
FontFamily="Arial" Foreground="Gray" FontWeight="Normal"
MinWidth="250" Binding="{Binding Path=Date}" >
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<fa:ImageAwesome Icon="Sort" Height="10" Name="Search" Margin="10,15,25,0" HorizontalAlignment="Center" />
<!--<TextBlock FontFamily="FontAwesome" FontSize="16" Text="" />-->
<TextBlock Text="Date" Margin="0,-30,0,0" />
</StackPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.Margin" Value="0,8,0,0"></Setter>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Background" Value="#dec15a" />
<Setter Property="Height" Value="50" />
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#d5b024" />
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.HeaderStyle>
</DataGridTextColumn>
</DataGrid.Columns>
How can I add a font awesome success icon next to the text like below when the rows is adding from code behind
Date | File| Status
03/14/2025|.pdf | Success (here the FontAwesome success icon should be shown)
Code-behind code is:
dgrd_ListFiles.Items.Add(new Item() { Date =
System.DateTime.Now.ToString("MM/dd /yyyy"), File=".pdf", Status = "Success" });
Share
Improve this question
edited Mar 17 at 18:00
marc_s
756k184 gold badges1.4k silver badges1.5k bronze badges
asked Mar 17 at 12:51
Vybhavi RVybhavi R
12 bronze badges
1
- I have used <DataGridTextColumn> for creating columns – Vybhavi R Commented Mar 17 at 13:08
1 Answer
Reset to default 0I think the following should work in your case. Modify the DataGridTextColumn.ElementStyle
tag as below:
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/>
<Setter Property="FrameworkElement.Margin" Value="0,8,0,0"/>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding}" />
<fa:ImageAwesome Icon="CheckCircle" Height="16" Width="16" Margin="5,0,0,0" Foreground="Green" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.ElementStyle>