Skip to content

Commit e348bc0

Browse files
Add final changes after review (fresh eye)
1 parent 13b8ad5 commit e348bc0

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

Readme.md

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,48 @@
55
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
66
<!-- default badges end -->
77

8-
# WPF Data Grid – Resize Row Height with a Splitter
8+
# WPF Data Grid – Resize Row Height
99

10-
This example configures the [`GridControl`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.GridControl) to resize row height with a splitter. The grid uses a custom control that stores row height in the [`RowData.RowState`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.RowData.RowState) property, so the height persists after refresh.
10+
This example implements resizable rows in a DevExpress WPF [Grid](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.GridControl). Users can interactively change the height of individual grid rows (similar to resizing columns) and retain these changes for a consistent user experience.
1111

1212
![Resize Row Height with a Splitter](./Images/resize-row-height.jpg)
1313

14-
Use this technique when you need to:
14+
## Implementation Details
1515

16-
* Allow users to resize rows manually.
17-
* Persist row height after a user updates data or scrolls a view.
18-
* Integrate a splitter into the row template.
16+
### Create a Resizable Control
1917

20-
## Implementation Details
18+
The `ResizableDataRow` control implements the `IResizeHelperOwner` interface to work with `ResizeHelper`. The control stores the current row height in the `RowHeight` property and updates this value when the splitter moves.
19+
20+
```csharp
21+
public class ResizableDataRow : Control, IResizeHelperOwner {
22+
public static readonly DependencyProperty RowHeightProperty =
23+
DependencyProperty.RegisterAttached("RowHeight", typeof(double), typeof(ResizableDataRow), new PropertyMetadata(20d));
24+
25+
double IResizeHelperOwner.ActualSize { get => RowHeight; set => RowHeight = value; }
26+
void IResizeHelperOwner.ChangeSize(double delta) {
27+
RowHeight = Math.Min(300, Math.Max(20, RowHeight + delta));
28+
}
29+
// ...
30+
}
31+
```
32+
33+
### Persist Row Height with an Attached Property
34+
35+
The `RowHeight` attached property stores the height value in the `RowState` object. The grid uses this value to restore the row height after scrolling or refreshing. The `ResizableDataRow` control gets and sets the row height through the `RowState`:
36+
37+
```csharp
38+
public static void SetRowHeight(DependencyObject element, double value) {
39+
element.SetValue(RowHeightProperty, value);
40+
}
2141

22-
1. Create a custom control that implements the `IResizeHelperOwner` interface.
23-
2. Add an attached `RowHeight` property to store the current height in the `RowState`.
24-
3. Define a `DataRowTemplate` for the view that includes the following:
25-
- A `ContentControl` bound to the [`DefaultDataRowTemplate`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.TableView.DefaultDataRowTemplate) to display the row content.
26-
- A custom `ResizableDataRow` control with a `RowSplitter` in its template.
27-
4. Bind the `ContentControl.Height` property to the `RowHeight` property to apply size changes.
42+
public static double GetRowHeight(DependencyObject element) {
43+
return (double)element.GetValue(RowHeightProperty);
44+
}
45+
```
2846

29-
### Row Template
47+
### Define a Row Template
48+
49+
The [`DataRowTemplate`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Grid.TableView.DataRowTemplate) contains a `ContentControl` that displays the default row content and a `ResizableDataRow` control with a `RowSplitter` to change the row height:
3050

3151
```xaml
3252
<DataTemplate x:Key="PersistentRowStateDataRowTemplate">
@@ -39,7 +59,7 @@ Use this technique when you need to:
3959
</Grid.RowDefinitions>
4060
<ContentControl Content="{Binding}"
4161
ContentTemplate="{Binding Path=View.DefaultDataRowTemplate}"
42-
Height="{Binding Path=RowState.(local:ResizableDataRow.RowHeight)}"/>
62+
Height="{Binding Path=RowState.(local:ResizableDataRow.RowHeight)}" />
4363
</Grid>
4464
</dx:MeasurePixelSnapper>
4565
<local:ResizableDataRow>
@@ -56,23 +76,6 @@ Use this technique when you need to:
5676
</DataTemplate>
5777
```
5878

59-
### Custom Control
60-
61-
The `ResizableDataRow` control implements the `IResizeHelperOwner` interface to work with `ResizeHelper`. The control stores the current row height in the `RowHeight` property and updates this value when the splitter moves.
62-
63-
```csharp
64-
public class ResizableDataRow : Control, IResizeHelperOwner {
65-
public static readonly DependencyProperty RowHeightProperty =
66-
DependencyProperty.RegisterAttached("RowHeight", typeof(double), typeof(ResizableDataRow), new PropertyMetadata(20d));
67-
68-
double IResizeHelperOwner.ActualSize { get => RowHeight; set => RowHeight = value; }
69-
void IResizeHelperOwner.ChangeSize(double delta) {
70-
RowHeight = Math.Min(300, Math.Max(20, RowHeight + delta));
71-
}
72-
// ...
73-
}
74-
```
75-
7679
## Files to Review
7780

7881
* [MainWindow.xaml](./CS/PersistentRowState/MainWindow.xaml) (VB: [MainWindow.xaml](./VB/PersistentRowState/MainWindow.xaml))

0 commit comments

Comments
 (0)