Click here to Skip to main content
15,921,156 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
How may I retrieve the final render size of width and height of RowHeader of a DataGrid in WPF ?

What I have tried:

In bellow code I tried, the final RenderSize of RowHeader should show in the Label. but doesn't work.
VB.NET
Class MainWindow
    Private data As New ObjectModel.ObservableCollection(Of Object)()
    Public Sub New()
        InitializeComponent()
        For i As Integer = 0 To 999
            data.Add(New With{.Column1=$"Row {i}",
                              .Column2=$"Value {i}{vbNewLine}JUST FOR FUN",
                              .Column3=$"Data {i}"})
        Next i
        WPF001.ItemsSource = data
    End Sub
End Class

XML
<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:RowHeaderFinalRenderSize"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <DataGrid x:Name="WPF001" AutoGenerateColumns="True"
            HorizontalAlignment="Center" VerticalAlignment="Top"
            Width="780" Height="307" Margin="0,10,0,0"/>
        <Label x:Name="lb" BorderThickness="1" BorderBrush="Black" Margin="325,368,325,10"
               Content="{Binding ElementName=WPF001, Path=RowHeader.RenderSize.Height, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
    </Grid>
</Window>
Posted
Updated 22-May-24 1:08am
v6

1 solution

Have you looked at the ActualSize properties?
 
Share this answer
 
Comments
Sh.H. 22-May-24 3:41am    
@Kevin Marois
Thanks for answer.
ActualSize is not RenderSize. RenderSize is the final size of UIElement after rendering and showing on the monitor. So it could be different value in monitors. But ActualSize is a static value.
Besides, ActualSize is for whole DataGrid. What I need is RenderSize of RowHeader not the whole DataGrid.
Jo_vb.net 22-May-24 4:54am    
It looks like, that we cannot understand how your project works.

Please add details to your question.
- describe data sources for DG1 + 2
- how is DG2 related to DG1
- is and how is the row height or rectangle size dependent from the data source
- how is the binding to the data source
Graeme_Grant 22-May-24 5:38am    
Take a look at his QA history. Bit of a help vampire.
Sh.H. 22-May-24 7:09am    
@Jo_vb.net
@Graeme_Grant
Updated.
Kindly please recheck.
Thanks.
Jo_vb.net 22-May-24 9:48am    
recheck result is => there is no bindable property for actual row height if default RowHeight == NaN !

You could only play around with code behind like the SO link shows:
https://stackoverflow.com/questions/55792661/wpf-how-to-get-height-of-each-row-in-datagrid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900