Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:23:17+00:00 2026-06-16T22:23:17+00:00

I got a problem with the GridSplitter Simple example code: <Grid x:Name=MainGrid> <Grid.RowDefinitions> <RowDefinition

  • 0

I got a problem with the GridSplitter

Simple example code:

<Grid x:Name="MainGrid">
    <Grid.RowDefinitions>
        <RowDefinition Height="100"></RowDefinition>
        <RowDefinition Height="2"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid x:Name="TopGrid" Grid.Row="0"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Red"/>
    <GridSplitter ResizeDirection="Rows" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="2" Background="Black" />
    <Grid x:Name="BottomGrid" Grid.Row="2" HorizontalAlignment="Stretch"  Background="Aquamarine" VerticalAlignment="Stretch"/>
</Grid>

This creates two Grids vertically seperated by a GridSplitter.

What I want to achieve is, that the GridSplitter automaticly align to the Grid´s content.
For example if I got a collapsable element in the bottom Grid, I want the top Grid to become bigger if I collapse the element. If I expand it, the top Grid should become smaller.

How do I do this? Later I will have 4 Grids with 3 GridSplitter´s… so the solution should work with multiple GridSplitter´s as well.

[edit]:

my xaml:

 <Grid x:Name="MainGrid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="100">
            <RowDefinition.MinHeight>
                <MultiBinding Converter="{StaticResource ResourceKey=MultiValueConverter}">
                    <Binding ElementName="dgStapelliste" Path="ActualHeight"></Binding>
                </MultiBinding>
            </RowDefinition.MinHeight>
        </RowDefinition>
        <RowDefinition Height="1"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition >           
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Grid.Column="0" x:Name="Test">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="200"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <WPF:DataGrid GridHeaderContent="{Binding StapelListe.HeaderText}" SelectedItem="{Binding StapelListe.SelectedItem}" Grid.Row="0" Grid.Column="0" x:Name="dgStapelliste" HorizontalAlignment="Stretch" ItemsSource="{Binding StapelListe, Mode=OneWay,  UpdateSourceTrigger=PropertyChanged}"/>
        <WPF:DataGrid GridHeaderContent="{Binding EinzelListe.HeaderText}" Grid.Row="0" Grid.Column="1" x:Name="dgEinzelliste" HorizontalAlignment="Stretch"  ItemsSource="{Binding EinzelListe, Mode=OneWay}"/>

        <GridSplitter Grid.Column="0" Width="1" VerticalAlignment="Stretch" Background="Black" />
    </Grid>

    <Grid Grid.Row="2" Grid.Column="0" Grid.RowSpan="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="200"/>
        </Grid.ColumnDefinitions>

        <WPF:DataGrid  GridHeaderContent="{Binding Anforderungsliste.HeaderText}" Grid.Column="0" x:Name="dgAnforderungsliste" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Anforderungsliste, Mode=OneWay}"/>

        <GridSplitter Grid.Column="0" Width="1" VerticalAlignment="Stretch" Background="Black" />
    </Grid>
    <GridSplitter Grid.Column="0" Grid.Row="1" Height="1" ResizeDirection="Rows"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black" x:Name="testSplitter" />
</Grid>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:23:18+00:00Added an answer on June 16, 2026 at 10:23 pm

    You could use MultiBinding to achieve what you want.

    For each RowDefinition you set a MinHeight which is bound to its contents ActualHeight’s like so:

    <RowDefinition Height="100">
        <RowDefinition.MinHeight>
            <MultiBinding Converter="{StaticResource ResourceKey=CalcAll}">
                <Binding ElementName="firstElementInThisRow" Path="ActualHeight"></Binding>
                <Binding ElementName="secondElementInThisRow" Path="ActualHeight"></Binding>
                <Binding ElementName="thirdElementInThisRow" Path="ActualHeight"></Binding>
                <Binding ElementName="fourthElementInThisRow" Path="ActualHeight"></Binding>
            </MultiBinding>
        </RowDefinition.MinHeight>
    </RowDefinition>
    

    Your Converter could look like:

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        double result = 0.0;
        foreach (object item in values)
        {
            result += System.Convert.ToDouble(item);
        }
        return result;
    }
    
    public object[] ConvertBack(object values, Type[] targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
    

    Everytime you expand a control, its ActualHeight changes and the Binding gets update -> MinHeight of the parents RowDefinition changes.

    But you cant set one if the controls VerticalAlignment to Stretch, because then the ActualHeight wouldn’t change by expanding.

    EDIT: Since the only property I can now think of is the DesiredSize.Height-property, you can’t use Binding (the binding won’t update, if the DesiredSize.Height-value changes).
    But perhaps you can use a property (let’s call it MinHeightRowOne) of type double which raises the PropertyChanged event in it’s setter and is bound to the first rows MinHeight (one property for each row):

    public double _minHeightRowOne;
    public double MinHeightRowOne
    {
        get
        {
            return _minHeightRowOne;
        }
        set
        {
            _minHeightRowOne = value;
            OnPropertyChanged("MinHeightRowOne");
        }
    }
    
    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(string name)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }
    

    <RowDefinition Height="100" MinHeight="{Binding Path=MinHeightRowOne}"/>
    

    Now add this EventHandler to the SizeChanged-Event of every control in the first row (one handler for each row):

    private List<KeyValuePair<string,double>> oldVals = new List<KeyValuePair<string,double>>();
    
    private void ElementInRowOneSizeChanged(object sender, SizeChangedEventArgs e)
    {
        FrameworkElement elem = (FrameworkElement)sender;
        MinHeightRowOne -= oldVals.Find(kvp => kvp.Key == elem.Name).Value;
        elem.Measure(new Size(int.MaxValue, int.MaxValue));
        MinHeightRowOne += elem.DesiredSize.Height;
        oldVals.Remove(oldVals.Find(kvp => kvp.Key == elem.Name));
        oldVals.Add(new KeyValuePair<string, double>(elem.Name, elem.DesiredSize.Height));
    }
    

    Through this the MinHeight of the Rows get updated everytime the Size of a control changes (which should include expanding or collapsing items).

    Note that every control must have an unique name to make this work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I got problem with scroll on my grid. Here is the code (nothing
I've got problem with my simple apliccation. I don't want paste tons of code.
i got problem with my code and hopefully someone able to figure it out.
I got problem with sending data in Android using httpPost. I found some example,
I want to ask about strcpy. I got problem here. Here is my code:
I got problem with this code #define twobit(ch) ((toupper(ch)) == 'S' ? 0LL :
I've got problem with my listview adapter. Please check my code below: public void
I've got problem with this peace of code, it should change lower case letters
I got problem with this code: if (!empty($_GET[ lic ])) $lic = $_GET[ lic
i got problem with my code , i am trying to get image from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.