Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your problem is that Canvas panels do not resize to fit their content.</p> <p>You refered to Measure and Arrange. Are you familiar with WPF's two pass layout system? Read this article for more information: <a href="http://msdn.microsoft.com/en-us/library/ms745058.aspx" rel="noreferrer">WPF's Layout System</a>.</p> <p>This article also describes what different panels do for layout. Each type of panel is different. </p> <p>In WPF, elements are first given an opportunity to determine what size they will be. Panels can determine their size based on the size of their children, or they can ask for fixed size regardless of the size of their children. Canvas is an example of the latter.</p> <p>Elements are next told what size they will be and asked to arrange themselves and their children.</p> <p>The Grid panel type not only allows rows and columns, but is also very good at auto sizing to content. </p> <p>The StackPanel type does not autosize at all in the dimension in which it is oriented, but it will autosize in the other dimension. </p> <p>Canvas can auto size to fill a space, but it never allows it's children to auto size. It draws its children at the specified coordinates and does not care how big they are.</p> <p>I would suggest trying a Grid with only one row/column.</p> <p>Or you could create a new Canvas class that has better autosizing capabilities. During measure, you would want to measure the child elements and size your Canvas accordingly. You might find a class like this helpful down the road. </p> <p>Here's an article on <a href="http://msdn.microsoft.com/en-us/library/ms748828.aspx" rel="noreferrer">Auto Layout</a> in WPF.</p> <p>If you want to create a custom panel, here's a subtopic on it: <a href="http://msdn.microsoft.com/en-us/library/ms754152.aspx#Panels_custom_panel_elements" rel="noreferrer">Custom Panel Elements</a>.</p> <p>EDIT: One more thing: You can also bind the width/height of the child element to the ActualWidth and ActualHeight properties on the canvas so that the child will adjust the size of its parent. You can use a converter to set a size ratio if necessary.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload