Reputation: 709
My goal is to create a usercontrol which will redraw when I change its size in designer. For simplicity I created usercontrol Cross. (I am rather a beginner in WPF).
Cross.xaml:
<UserControl x:Class="WpfApplication2.Cross"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Name="Grid1">
</Grid>
</UserControl>
Cross.xaml.cs (without using statements):
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for Cross.xaml
/// </summary>
///
public partial class Cross : UserControl
{
public Cross()
{
InitializeComponent();
Line l = new Line();
l.X1 = 0; l.Y1 = 0; l.X2 = 300; l.Y2 = 300;
l.Stroke = new SolidColorBrush(Colors.Black);
Grid1.Children.Add(l);
l = new Line();
l.X1 = 0; l.Y1 = 300; l.X2 = 300; l.Y2 = 0;
l.Stroke = new SolidColorBrush(Colors.Black);
Grid1.Children.Add(l);
}
}
}
So when I change the size of a Cross in designer from 300 to 600 I want there 2 lines - [0,0,600,600], [0,600,600,0] rather than [0,0,300,300], [0,300,300,0].
Upvotes: 0
Views: 5814
Reputation: 54562
Try using The ViewBox
Control , Change your xaml to
<UserControl x:Class="WpfApplication2.Cross"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Viewbox>
<Grid Name="Grid1"/>
</Viewbox>
</Grid>
</UserControl>
Upvotes: 4