Resize canvas to window / user control size

12,188

Solution 1

You can put the canvas within a Viewbox. This will allow you to stretch it to fill the window, while designing it at a constant size.

Solution 2

How about removing specified width and height

<canvas Name="svg2383">
<---->
</canvas>

EDIT: Another way is to use a binding as follows:

<Window x:Name="MainWin">
   <Canvas Width="{Binding ElementName=MainWin, Path=ActualWidth}"
      Height="{Binding ElementName=MainWin, Path=ActualHeight}">
   <--->
   </Canvas>
</Window>
Share:
12,188
Admin
Author by

Admin

Updated on September 03, 2022

Comments

  • Admin
    Admin over 1 year

    Hi I convert SVG image to XAML/canvas. I would like set this canvas as window/user control background.

    Something like this:

        <Window x:Class="WpfApplication2.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                Title="MainWindow" Height="350" Width="525">
    
        <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    Name="svg2383" Width="800" Height="600">
    
        <---->
        </Canvas>
        </Window>
    

    My problem is Canvas is too much big, I would like automatic resize/stretch canvas on window height/width.

    Image on canvas is complicated..http://kde-look.org/content/show.php/something_wall?content=115863

    So set Width and Height is not solution, because this canvas consist other canvas.

  • Admin
    Admin over 13 years
    So set Width and Height is not solution, because this canvas consist other canvas. So canvas has other canvas and he has other canvas, I must set many properties height and width...this is not solution.
  • Admin
    Admin over 13 years
    Ok, but I would like have canvas as background, because I want put some controls on this background. If I use viewbox, in view box I must put canvas and in canvas I must put control as grid with other controls. I think it’s no good.
  • Reed Copsey
    Reed Copsey over 13 years
    @jminarik: Make a separate canvas - use it for your other controls, and put the Viewbox and it in a Grid. Should work fine.