|
1 |
| -# How to load images in a cell in winui treegrid? |
2 |
| -This example describes how to load images in a cell in winui treegrid. |
| 1 | +# How to load images in a cell in WinUI TreeGrid? |
| 2 | + |
| 3 | +This example describes how to load images in a cell in WinUI TreeGrid. |
| 4 | + |
| 5 | +You can add the image to [WinUI TreeGrid](https://www.syncfusion.com/winui-controls/treegrid) (SfTreeGrid) cell by using **TreeGridTemplateColumn**. |
| 6 | + |
| 7 | +### XAML |
| 8 | + |
| 9 | +``` xml |
| 10 | +<treeGrid:SfTreeGrid Name="treeGrid" |
| 11 | + AutoGenerateColumns="False" |
| 12 | + AutoExpandMode="RootNodesExpanded" |
| 13 | + ChildPropertyName="ReportsTo" |
| 14 | + AllowResizingColumns="True" |
| 15 | + NavigationMode="Cell" |
| 16 | + AllowEditing="True" |
| 17 | + SelfRelationRootValue="-1" |
| 18 | + SelectionMode="Single" |
| 19 | + ItemsSource="{Binding EmployeeDetails}" > |
| 20 | + <treeGrid:SfTreeGrid.Columns> |
| 21 | + <treeGrid:TreeGridTextColumn MappingName="FirstName"/> |
| 22 | + <treeGrid:TreeGridTextColumn MappingName="LastName"/> |
| 23 | + <treeGrid:TreeGridNumericColumn HeaderText="Employee ID" MappingName="ID" /> |
| 24 | + <treeGrid:TreeGridTextColumn MappingName="Title"/> |
| 25 | + <treeGrid:TreeGridTemplateColumn HeaderText="Country" MappingName="ImageLink"> |
| 26 | + <treeGrid:TreeGridTemplateColumn.CellTemplate> |
| 27 | + <DataTemplate> |
| 28 | + <Grid> |
| 29 | + <Image Width="30" |
| 30 | + Height="20" |
| 31 | + Source="{Binding ImageLink, |
| 32 | + Converter={StaticResource converter}}" /> |
| 33 | + </Grid> |
| 34 | + </DataTemplate> |
| 35 | + </treeGrid:TreeGridTemplateColumn.CellTemplate> |
| 36 | + </treeGrid:TreeGridTemplateColumn> |
| 37 | + </treeGrid:SfTreeGrid.Columns> |
| 38 | +</treeGrid:SfTreeGrid> |
| 39 | +``` |
| 40 | + |
| 41 | +### C# |
| 42 | + |
| 43 | +``` csharp |
| 44 | +class StringToImageConverter : IValueConverter |
| 45 | +{ |
| 46 | + public object Convert(object value, Type targetType, object parameter, string language) |
| 47 | + { |
| 48 | + string imageName = value.ToString(); |
| 49 | + if (imageName == "US.jpg") |
| 50 | + { |
| 51 | + Uri uri = new Uri("ms-appx:///Images/US.jpg"); |
| 52 | + BitmapImage image = new BitmapImage(uri); |
| 53 | + return image; |
| 54 | + } |
| 55 | + |
| 56 | + else if (imageName == "UK.jpg") |
| 57 | + { |
| 58 | + Uri uri1 = new Uri("ms-appx:///Images/UK.jpg"); |
| 59 | + BitmapImage image = new BitmapImage(uri1); |
| 60 | + return image; |
| 61 | + } |
| 62 | + |
| 63 | + else |
| 64 | + { |
| 65 | + Uri uri1 = new Uri("ms-appx:///Images/Japan.jpg"); |
| 66 | + BitmapImage image = new BitmapImage(uri1); |
| 67 | + return image; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public object ConvertBack(object value, Type targetType, object parameter, string language) |
| 72 | + { |
| 73 | + throw new NotImplementedException(); |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
0 commit comments