There is an application with a placed Canvas in it, you need to set markers on the edges of the Canvas so that when you capture and move the marker, you can resize the Canvas itself. I can't figure out how to draw these markers on the edges of the canvas.

XAML

<Grid Background="DarkGray" DockPanel.Dock="Left"> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <ItemsControl Name="GeneralItemsControl" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Beige" ItemsSource="{Binding Shapes}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas Name="GeneralCanvas" Width="300" Height="250" Background="White" IsItemsHost="True" MouseLeftButtonDown="OnMouseLeftButtonDown" MouseLeftButtonUp="OnMouseLeftButtonUp" MouseMove="OnMouseMove" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style> <!-- а это привязка координат контейнера к VM --> <Setter Property="Canvas.Left" Value="{Binding Position.X}" /> <Setter Property="Canvas.Top" Value="{Binding Position.Y}" /> </Style> </ItemsControl.ItemContainerStyle> </ItemsControl> </ScrollViewer> </Grid> 
  • Probably, this is a canvas and markers for it should be placed in another canvas - Andrey NOP
  • @AndreyNOP I think the same way, but ItemsControl does not allow using more than one item - KJfe
  • What does the ItemsControl? Either place it in the Canvas itself, or do it inside the ItemsPanelTemplate. I recommend that you first get rid of all the excess, make a simple layout of the canvas and markers / elements inside it. Implement your idea on such a simple layout, and then shove it all into ItemsControl or wherever you want. - Andrey NOP
  • 2
    use the standard GridSplitter : Canvas placed in the Grid cell, in the narrow neighboring cells above / below / left / right we place one GridSplitter , and for those that need to work horizontally, set VerticalAlignment="Stretch" HorizontalAlignment="Center" , and for vertical ones respectively VerticalAlignment="Center" HorizontalAlignment="Stretch" . - Alias

1 answer 1

Let me illustrate what @Alias ​​meant in my comment.

You instead of Canvas ' and use this structure:

 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="0"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="0"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="0"/> <RowDefinition Height="*"/> <RowDefinition Height="0"/> </Grid.RowDefinitions> <GridSplitter Grid.Row="1" Grid.Column="1" Height="100" Width="10" HorizontalAlignment="Left" VerticalAlignment="Center" ResizeDirection="Columns"/> <GridSplitter Grid.Row="1" Grid.Column="1" Height="100" Width="10" HorizontalAlignment="Right" VerticalAlignment="Center" ResizeDirection="Columns"/> <GridSplitter Grid.Row="1" Grid.Column="1" Height="10" Width="100" VerticalAlignment="Top" HorizontalAlignment="Center" ResizeDirection="Rows"/> <GridSplitter Grid.Row="1" Grid.Column="1" Height="10" Width="100" VerticalAlignment="Bottom" HorizontalAlignment="Center" ResizeDirection="Rows"/> <Canvas Background="LightGray" Grid.Row="1" Grid.Column="1" Margin="10"/> </Grid> 

It turns out:

uncertain move