How to relative scale size of User Control?

Peter Stegnar picture Peter Stegnar · Sep 13, 2009 · Viewed 26.5k times · Source

How to relative scale size of User Control like image (in image editor).

Example (100%):

alt text
(source: stegnar.com)

Scaled down UC (70%):

alt text
(source: stegnar.com)

Well I achieve this in picture editor, but I would like in WPF. :) I need this to adjust my application to different screen resolution, while nothing hiding (no scrollbars).

Answer

Milan Nankov picture Milan Nankov · Sep 13, 2009

You could try the ViewBox control that scales up/down its content so that it fills the available space.

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="Window1">
<Grid>
    <Viewbox StretchDirection="Both" Stretch="Uniform">
        <local:UserControl1 Height="600" Width="600"/>
    </Viewbox>
</Grid>