Can I use the mouse to drag or resize the canvas?

I use a canvas with an expander built into it, so when the expander expands, it imposes the controls below.

        <Canvas Grid.Row="0" Panel.ZIndex="99">
            <Border Width="450" BorderThickness="1">
                <Expander etc />
            </Border>
        </Canvas>
        <OtherControls Grid.Row="1"/> etc

Instead of setting the canvas size, is there a way to allow the user to drag and drop its size?

+3
source share
1 answer

here's the thought: put everything in a grid. Let the grid automatically resize, place the canvas on the grid (make sure it occupies the entire grid) so that it matches the size of the parent:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <Canvas Background="Transparent" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

    <Border Width="450" BorderThickness="1">
            <Expander etc />
    </Border>

    <OtherControls Grid.Row="1"/>
</Grid>

not sure how appropriate this is, but check out this post. Maybe this will give you some ideas (I wrote that 4 years ago I remembered specifics for too long, but it compiles and runs the code):

http://denismorozov.blogspot.com/2008/01/how-to-resize-wpf-controls-at-runtime.html

0
source

Source: https://habr.com/ru/post/1794799/


All Articles