[英]WPF usercontrol resizing
我的目標是創建一個用戶控件,當我在設計器中更改其大小時會重繪。 為簡單起見,我創建了usercontrol Cross。 (我是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 (不使用using語句):
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);
}
}
}
因此,當我將設計器中Cross的大小從300更改為600時,我希望有2行-[0,0,600,600],[0,600,600,0],而不是[0,0,300,300],[0,300,300,0]。
嘗試使用ViewBox
控件,將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>
<Viewbox>
<Grid Name="Grid1"/>
</Viewbox>
</Grid>
</UserControl>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.