WPF Extender Will Not Expand Left When Inside Canvas

I have a grid with 4 columns. In the first column is a canvas with ZIndex 99 and inside of which is an expander. The extension direction is set to RIGHT. When I click on the header, the expander expands the OVER TOP of column 2 ... this is exactly what I want. I am trying to reproduce this (only the opposite direction) inside column 4, so that when it expands it will appear above column 3. Although I put the ExpandDirection of the second expander in β€œLeft”, it still expands to the right and from the screen.

Here is the working expander:

<Canvas Grid.Column="0" Panel.ZIndex="99" Grid.RowSpan="4" VerticalAlignment="Stretch" Margin="0,5"> 
    <Expander ExpandDirection="Right" Style="{DynamicResource OptionsExpanderStyle}" VerticalAlignment="Stretch" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">
        <Border BorderBrush="Black" BorderThickness="0,0,2,0">
            <Grid Background="White">

            </Grid>
        </Border>
    </Expander>
</Canvas>

Here is a broken expander:

<Canvas x:Name="rightCanvas" Panel.ZIndex="99" Grid.RowSpan="4" Grid.Column="3" Margin="0,5">
    <Expander ExpandDirection="Left" Style="{DynamicResource OptionsExpanderStyle}" HorizontalAlignment="Right" VerticalAlignment="Stretch" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">
        <Border BorderBrush="Black" BorderThickness="2,0,0,0">
            <Grid Background="White" Width="150">

            </Grid>
        </Border>
    </Expander>
</Canvas>
+3
source share
1 answer

Do not use canvas.

Try something like this:

<Grid>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <TextBlock Background="LightBlue"
            TextAlignment="Center" Text="Left Column"/>
        <TextBlock Grid.Column="1" Background="LightCoral" 
            TextAlignment="Center" Text="Right Column"/>
    </Grid>
    <Expander Background="LightGray" ExpandDirection="Right"
        Header="LeftMenu" VerticalAlignment="Top" HorizontalAlignment="Left">
        <StackPanel Width="200">
            <TextBlock Text="Some menu stuff"/>
            <TextBlock Text="Some more"/>
        </StackPanel>   
    </Expander>
    <Expander Background="LightGray" ExpandDirection="Left"
        Header="RightMenu" VerticalAlignment="Top" HorizontalAlignment="Right">
        <StackPanel Width="200" >
            <TextBlock Text="Some menu stuff"/>
            <TextBlock Text="Some more"/>
        </StackPanel>
    </Expander>
</Grid>
+3
source

All Articles