How to make Column with image(icon) and text
Hi,
I went through all the documentation on Datagrid columns, but still, can't figure out is there a possibility to make a column that has an icon before the text, I'm trying to do something like this:
Also, I've found a very similar question with an answer, but unfortunately for me, it was for WinForms not for the WPF solution.
https://www.syncfusion.com/forums/153880/solved-how-to-add-custom-column-icon-and-text-on-datagrid
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
VS
Vijayarasan Sivanandham
Syncfusion Team
September 7, 2021 12:25 PM UTC
Hi David Suarez,
Thank you for contacting Syncfusion Support.
Your requirement can be achieved by loaded the Image and TextBlock has CellTemplate in GridTemplateColumn in SfDataGrid. Please refer the below code snippet,
XAML Code Snippet:
Thank you for contacting Syncfusion Support.
Your requirement can be achieved by loaded the Image and TextBlock has CellTemplate in GridTemplateColumn in SfDataGrid. Please refer the below code snippet,
XAML Code Snippet:
|
<syncfusion:GridTemplateColumn MappingName="Trustworthiness" HeaderText="Trustworthiness">
<syncfusion:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Source="{Binding Trustworthiness,
Converter={StaticResource trustImageConverter}}"
Height="15" Width="15" Grid.Column="0"/>
<TextBlock Text="{Binding Trustworthiness}" Padding="4"
VerticalAlignment="Center" Grid.Column="1"/>
</Grid>
</DataTemplate>
</syncfusion:GridTemplateColumn.CellTemplate>
<syncfusion:GridTemplateColumn.EditTemplate>
<DataTemplate>
<TextBox Text="{Binding Trustworthiness}" Padding="4"
VerticalAlignment="Center" Grid.Column="1"/>
</DataTemplate>
</syncfusion:GridTemplateColumn.EditTemplate>
</syncfusion:GridTemplateColumn> |
C# Code Snippet:
|
internal class TrustImageConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo info)
{
if (value == null || string.IsNullOrEmpty(value.ToString()))
return null;
else
return @"Images/"+ value.ToString()+".png";
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo info)
{
throw new NotImplementedException();
}
} |
For more information related to GridTemplateColumn, please refer the user guide documentation,
Please let us know if you have any concerns in this.
Regards,
Vijayarasan S
Regards,
Vijayarasan S
Marked as answer
DS
David Suarez
September 8, 2021 04:56 AM UTC
Thank you, for the solution, this helped me =)
VS
Vijayarasan Sivanandham
Syncfusion Team
September 8, 2021 05:30 AM UTC
Hi David Suarez,
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.
Regards,
Vijayarasan S
Thanks for the update.
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.
Regards,
Vijayarasan S
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
DS David Suarez
- Sep 6, 2021 01:53 PM UTC
- Sep 8, 2021 05:30 AM UTC