<p>I have a 3 column grid in a window with a GridSplitter on the first column. I want to set the MaxWidth of the first column to a third of the parent Window or Page <code>Width</code> (or <code>ActualWidth</code>) and I would prefer to do this in XAML if possible.</p>

<p>This is some sample XAML to play with in XamlPad (or similar) which shows what I'm doing. </p>

<pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" &gt;
    &lt;Grid&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition x:Name="Column1" Width="200"/&gt;
            &lt;ColumnDefinition x:Name="Column2" MinWidth="50" /&gt;
            &lt;ColumnDefinition x:Name="Column3" Width="{ Binding ElementName=Column1, Path=Width }"/&gt;
            &lt;/Grid.ColumnDefinitions&gt;

        &lt;Label Grid.Column="0" Background="Green" /&gt;
        &lt;GridSplitter Grid.Column="0" Width="5" /&gt;
        &lt;Label Grid.Column="1" Background="Yellow" /&gt;
        &lt;Label Grid.Column="2" Background="Red" /&gt;
    &lt;/Grid&gt;
&lt;/Page&gt;
</code></pre>

<p>As you can see, the right column width is bound to the width of the first column, so when you slide the left column using the splitter, the right column does the same :)
If you slide the left column to the right, eventually it will slide over half the page/window and over to the right side of the window, pushing away column 2 and 3. </p>

<p>I want to prevent this by setting the MaxWidth of column 1 to a third of the window width (or something like that). I can do this in code behind quite easily, but how to do it in "XAML Only"?</p>

<p><strong><em>EDIT:</strong> David Schmitt suggested to use SharedSizeGroup instead of binding, which is an excellent suggestion. My sample code would look like this then:</em></p>

<pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" &gt;
        &lt;Grid IsSharedSizeScope="True"&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition x:Name="Column1" SharedSizeGroup="ColWidth" Width="40"/&gt;
                &lt;ColumnDefinition x:Name="Column2" MinWidth="50" Width="*" /&gt;
                &lt;ColumnDefinition x:Name="Column3" SharedSizeGroup="ColWidth"/&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;Label Grid.Column="0" Background="Green" /&gt;
            &lt;GridSplitter Grid.Column="0" Width="5" /&gt;
            &lt;Label Grid.Column="1" Background="Yellow" /&gt;
            &lt;Label Grid.Column="2" Background="Red" /&gt;
        &lt;/Grid&gt;
&lt;/Page&gt;
</code></pre>

[{'answer_id': 85173, 'author': 'Thomas', 'author_id': 9970, 'author_profile': 'https://Stackoverflow.com/users/9970', 'pm_score': 0, 'selected': False, 'text': '<p>Too lazy to actually write it up myself, but you should be able to use a mathematical converter and bind to your parent windows width (either by name, or with a RelativeSource ancestor search).  </p>\n\n<pre><code>//I know I borrowed this from someone, sorry I forgot to add a comment from whom\npublic class ScaledValueConverter : IValueConverter\n{\n  public Object Convert(Object value, Type targetType, Object parameter, System.Globalization.CultureInfo culture)\n  {\n     Double scalingFactor = 0;\n     if (parameter != null)\n     {\n        Double.TryParse((String)(parameter), out scalingFactor);\n     }\n\n     if (scalingFactor == 0.0d)\n     {\n        return Double.NaN;\n     }\n\n     return (Double)value * scalingFactor;\n  }\n\n  public Object ConvertBack(Object value, Type targetType, Object parameter, System.Globalization.CultureInfo culture)\n  {\n     throw new Exception("The method or operation is not implemented.");\n  }\n}\n</code></pre>\n'}, {'answer_id': 157780, 'author': 'Christopher Bennage', 'author_id': 6855, 'author_profile': 'https://Stackoverflow.com/users/6855', 'pm_score': 4, 'selected': True, 'text': '<p>I think the XAML-only approach is somewhat circuitous, but here is a way to do it.</p>\n\n<pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \n      xmlns:sys="clr-namespace:System;assembly=mscorlib"\n      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" &gt;\n\n    &lt;!-- This contains our real grid, and a reference grid for binding the layout--&gt;\n    &lt;Grid x:Name="Container"&gt;\n\n      &lt;!-- hidden because it\'s behind the grid below --&gt;\n      &lt;Grid x:Name="LayoutReference"&gt;\n        &lt;Grid.ColumnDefinitions&gt;\n          &lt;ColumnDefinition Width="*"/&gt;\n          &lt;ColumnDefinition Width="*"/&gt;\n          &lt;ColumnDefinition Width="*"/&gt;\n        &lt;/Grid.ColumnDefinitions&gt;\n        &lt;!-- We need the border, because the column doesn\'t have an ActualWidth --&gt;\n        &lt;Border x:Name="ReferenceBorder" \n                Background="Black" /&gt;\n        &lt;Border Background="White" Grid.Column="1" /&gt;\n        &lt;Border Background="Black" Grid.Column="2" /&gt;\n      &lt;/Grid&gt;\n\n      &lt;!-- I made this transparent, so we can see the reference --&gt;\n      &lt;Grid Opacity="0.9"&gt;\n          &lt;Grid.ColumnDefinitions&gt;\n              &lt;ColumnDefinition x:Name="Column1" \n                                MaxWidth="{Binding ElementName=ReferenceBorder,Path=ActualWidth}"/&gt;\n              &lt;ColumnDefinition x:Name="Column2" \n                                MinWidth="50"  /&gt;\n              &lt;ColumnDefinition x:Name="Column3" \n                                Width="{ Binding ElementName=Column1, Path=Width }"/&gt;\n              &lt;/Grid.ColumnDefinitions&gt;\n\n          &lt;Label Grid.Column="0" Background="Green"/&gt;\n          &lt;GridSplitter Grid.Column="0" Width="5" /&gt;\n          &lt;Label Grid.Column="1" Background="Yellow" /&gt;\n          &lt;Label Grid.Column="2" Background="Red" /&gt;\n      &lt;/Grid&gt;\n    &lt;/Grid&gt;\n\n&lt;/Page&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/82323', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6415/']