Skip to content

Commit 6b548f3

Browse files
Merge pull request #1236 from telerik/new-kb-remembering-restoring-expanded-rows-treedatagrid-dotnet-maui-018e1ff5877a4d198116f5f50b11bfb7
Added new kb article remembering-restoring-expanded-rows-treedatagrid-dotnet-maui
2 parents dbcfb43 + 7c00620 commit 6b548f3

File tree

3 files changed

+102
-6
lines changed

3 files changed

+102
-6
lines changed

knowledge-base/attaching-images-dotnet-maui-chat.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ I want to know how to attach an image in the .NET MAUI Chat and display the imag
2121
This knowledge base article also answers the following questions:
2222
- How to upload an image in .NET MAUI Chat?
2323
- How to create a custom template for images in .NET MAUI Chat?
24-
- How to use ItemTemplateSelector to manage media content in .NET MAUI Chat?
24+
- How to use `ItemTemplateSelector` to manage media content in .NET MAUI Chat?
2525

2626
## Solution
2727

@@ -115,13 +115,13 @@ add additional elements here <ImageButton /> or <telerik:RadTemplatedButton />
115115

116116
Use the following steps to display images in the chat:
117117

118-
1. Implement the logic for uploading images in the button's command.
118+
**1.** Implement the logic for uploading images in the button's command.
119119
>note To handle image uploads in .NET MAUI, you need to ensure your application has the necessary permissions to access the device's storage and camera.
120120
121-
2. Create a custom `ItemTemplate` to display image messages.
122-
3. Use the `ItemTemplateSelector` to dynamically choose templates based on message content.
121+
**2.** Create a custom `ItemTemplate` to display image messages.
122+
**3.** Use the `ItemTemplateSelector` to dynamically choose templates based on message content.
123123

124-
Follow the steps outlined in the [ItemTemplateSelector documentation](https://docs.telerik.com/devtools/maui/controls/chat/item-template-selector) to configure this functionality.
124+
Follow the steps outlined in the [`ItemTemplateSelector` documentation](https://docs.telerik.com/devtools/maui/controls/chat/item-template-selector) to configure this functionality.
125125

126126
Example of an `ItemTemplate` for rendering messages with images:
127127

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Remembering and Restoring Expanded Rows in TreeDataGrid for .NET MAUI
3+
description: Learn how to efficiently remember expanded rows and restore them in TreeDataGrid for .NET MAUI.
4+
type: how-to
5+
page_title: Efficiently Remember and Restore Expanded Rows in TreeDataGrid for .NET MAUI
6+
meta_title: Efficiently Remember and Restore Expanded Rows in TreeDataGrid for .NET MAUI
7+
slug: remembering-restoring-expanded-rows-treedatagrid-dotnet-maui
8+
tags: treedatagrid, .net maui, expand, collapse, isexpanded, isexpandablebinding
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
| Version | Product | Author |
15+
| --- | --- | ---- |
16+
| 11.1.0 | Telerik UI for .NET MAUI TreeDataGrid | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) |
17+
18+
## Description
19+
20+
I want to remember the expanded rows in the TreeDataGrid and restore them later. What is the most efficient way to achieve this?
21+
22+
This knowledge base article also answers the following questions:
23+
- How can I store expanded items in TreeDataGrid for later use?
24+
- How can I restore the expansion state in TreeDataGrid after changes?
25+
- What is the best way to manage expanded rows in TreeDataGrid?
26+
27+
## Solution
28+
29+
To achieve the scenario you can use one of the following approaches:
30+
* [Using `Expand` and `Collapse` methods](#using-expand-and-collapse-methods)
31+
* [Using `IsExpandableBinding` property of the `TreeDataGridDescriptor`](#using-isexpandablebinding)
32+
33+
### Using Expand and Collapse Methods
34+
35+
To achieve this, follow these steps:
36+
37+
1. Use `Expand()` and `Collapse()` methods to expand or collapse items.
38+
2. Use the `IsExpanded` method to check whether an item is expanded.
39+
3. Store the expanded items in a collection, such as a `List<YourDataClass>`.
40+
4. Iterate through the collection to restore the expanded state by calling the `Expand()` method.
41+
42+
```C#
43+
public partial class MainPage : ContentPage
44+
{
45+
public MainPage()
46+
{
47+
InitializeComponent();
48+
this.BindingContext = new ViewModel();
49+
}
50+
51+
// Collection for storing expanded items
52+
List<Data> expandedItems = new List<Data>();
53+
54+
private void Button_Clicked(object sender, EventArgs e)
55+
{
56+
var items = (IEnumerable)this.tdg.ItemsSource;
57+
this.expandedItems = new List<Data>();
58+
AddExpandedItems(items, expandedItems);
59+
}
60+
61+
private void AddExpandedItems(IEnumerable items, List<Data> expandedItems)
62+
{
63+
foreach (Data item in items)
64+
{
65+
if (this.tdg.IsExpanded(item))
66+
{
67+
expandedItems.Add(item);
68+
}
69+
70+
IEnumerable childrenOfTheItem = item.Children;
71+
AddExpandedItems(childrenOfTheItem, expandedItems);
72+
}
73+
}
74+
75+
private void Button2_Clicked(object sender, EventArgs e)
76+
{
77+
foreach (Data item in this.expandedItems)
78+
{
79+
this.tdg.Expand(item);
80+
}
81+
}
82+
}
83+
```
84+
85+
### Using `IsExpandableBinding`
86+
87+
As an alternative, use the [`IsExpandableBinding`](https://docs.telerik.com/devtools/maui/controls/treedatagrid/descriptor) property at the descriptor level. This approach provides direct control over the expandability of rows via data binding.
88+
89+
1. Add a `bool` property in the data model to indicate whether an item is expandable.
90+
2. Bind this property to the `IsExpandableBinding` property of the TreeDataGrid descriptor.
91+
3. Implement the logic in button clicks to get and restore expanded items.
92+
93+
## See Also
94+
95+
- [TreeDataGrid Overview](https://docs.telerik.com/devtools/maui/controls/treedatagrid/overview)
96+
- [Expand and Collapse Methods in TreeDataGrid](https://docs.telerik.com/devtools/maui/controls/treedatagrid/methods)

styling-and-themes/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ After applying the `Purple` swatch, the ToggleButton looks like this:
124124
125125
## Applying Theme Colors throughout the App
126126

127-
You can use the colors provided by the Telerik theming mechanism and apply them everywhere in your application. Each theme swatch provides a set of colors that you can use in parts of your app that aren't Telerik components. This allows you to achieve a consistent look and feel.
127+
You can use the colors provided by the Telerik theme and its swatches. Each theme swatch provides a set of colors that you can use in parts of your app that aren't Telerik components. This allows you to achieve a consistent look & feel.
128128

129129
For example, you can use the `RadAppSurfaceColor` and `RadOnAppSurfaceColor` colors for background/text color respectively, and `RadPrimaryColor` for the accent color to match the appearance of the Telerik controls:
130130

0 commit comments

Comments
 (0)