Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
415
Setting Grid's rowdefinition programatically
posted

Hi,

I have a UserControl which itself contains 2usercontrols(XAM datagrid ). i have set Grid's Rowdefinition currently as *,Auto.

if there is huge data in 2nd XAMdatagrid it hides 1st one. i can set rowdefinition fixed .5* for second but 1st XAMDatagrid is parent grid and there may or may not childs in 2nd XAMDatagrid. so in that case half page will be empty.

i need to sent 2nd RowDefinition programmaticaly, if there are childrens it shd be .5* not it shd be auto. Is there any propery of XAMDatagrid which can be used to find number of Rows so that we can set DataTrigger for 2nd RowDefinition to find if rows exist in 2nd XAMDatagrid?

Regards

Hitesh

Parents
No Data
Reply
  • 2490
    Verified Answer
    Offline posted

    Hello Hitesh,

    In order to change the RowDefinition's Height, depending on the number of records, you can use a DataTrigger bound to the Xamdatagrid's Records.Count property.
    To illustrate this I have prepared a custom application for you. For example:

           <Grid.RowDefinitions>
                <RowDefinition>
                    <RowDefinition.Style>
                        <Style>
                            <Setter Property="RowDefinition.Height" Value="*"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=xamDataGrid2, Path=Records.Count}" Value="6">
                                    <Setter Property="RowDefinition.Height" Value="100"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </RowDefinition.Style>
                </RowDefinition>

    It consists of an User control with two Xamdatagrids. The Height of the first one depends on the number of records of the second one. Try deleting a few records it will change in a custom manner.


    Another approach could be through the code behind:

     layout1.RowDefinitions[0].Height = new GridLength(5);

    If this example does not illustrate your scenario, please modify the sample application I have provided so the issue is reproduced and send it back to me. Having this information will help me further investigate this matter for you.

    Looking forward to hear from you.

    XamDataGrid_SetRowdefinition.zip
Children