Search code examples
wpfgridwidthribbon

WPF: Star in ColumnDefinition not expanding columns


I have a user control that need the 1st and 3rd column to have the same width at all time. My code is a follows:

<UserControl x:Class="UserControls.ListBoxSelector"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="5*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="5*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ListBox x:Name="ListBox_Source" Grid.Column="0" Grid.Row="0" />
        <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Vertical">
            <Button Content="&gt;" Click="Button_Add_Click"/>
            <Button Content="&lt;" Click="Button_Remove_Click" />
        </StackPanel>
        <ListBox x:Name="ListBox_Destination" Grid.Column="2" Grid.Row="0" />
    </Grid>
</UserControl>

The result is not as expected as column 3 (ListBox_Destination) is not expanded at all. Isn't the 5* in ColumnDefinition enough to force the 2 listbox to the same width??

UPDATED : Sorry that I forgot to mention that the problem only occurs when I put the control inside a RibbonGroup using Microsoft Ribbon for WPF


Solution

  • Sometimes, when you put your control in certian types of layout controls (like a StackPanel), it won't size as expected because the parent layout will only size the child to it's minimum desired size (just enough to show the content). This may be why you are seeing this when you put it in the RibbonGroup. Try giving your Grid a Width or MinWidth and see if that makes a difference.