1
votes

So i was wondering if its posible to stretch a expander on a page when having HorizontalAlignment set to left on a Usercontrol/page.

The problem is that we dont want to set a width on the expander because we want it to resize when resizing the application. We also cant set a minwidth on the expander because our application also has a minwidth of 850 and a normal width of 1200 and we want the expander always stretch to the maximum size.

Code sample:

<UserControl x:Class="WpfApp1.Window1"
        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:WpfApp1"
        mc:Ignorable="d"
        d:DesignWidth="1100" HorizontalAlignment="Left">
  <DockPanel>
    <StackPanel>
      <Expander Background="LightBlue"/>
    </StackPanel>
  </DockPanel>
</UserControl>

Our main goal is to create something like the image below where the radio button is always on the right and the expander sizes to it's avaible space.

enter image description here

3

3 Answers

1
votes

If you are using DockPanel just use its Dock property for child elements and set LastChildFill="True" (Expander should be the last child element of course).

Something like this:

<DockPanel LastChildFill="True">
     <RadioButton DockPanel.Dock="Right" Content="Active"/>
     <Expander DockPanel.Dock="Left" Header="title1" Background="LightBlue"/>
</DockPanel>
0
votes

Can you set the HorizontalAlignment to Stretch where you are using your control?

<Window ...>
    <Grid>
        <local:Window1 HorizontalAlignment="Stretch"></local:MainWindow>
    </Grid>
</Window>

(Where local:Window1 is your user control as defined in the question)

0
votes

We solved the isue by using a grid with column width set to auto and * in the expander header:

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