【发布时间】:2019-10-25 04:20:00
【问题描述】:
我正在创建一个 UWP 应用。在应用程序中,我创建了一个用户控件,其中有一个设置大小的矩形。尺寸为 700x700。我还将用户控件设置为 700x700。
我认为它会起作用的是,当开发人员将用户控件放在页面上时,用户控件将出现,大小为 700x700。
但是,用户控件的显示尺寸为 100x100!
这是我在工具栏中双击用户控件以将其添加到页面后的页面代码。
<Custom:Control HorizontalAlignment="Left" Height="100" Margin="254,158,0,0" VerticalAlignment="Top" Width="100"/>
注意高度和宽度是 100x100!
我在 XAML 和类构造函数中将 Usercontrol 的 Height 和 Width 属性设置为 700x700。什么都没有改变!
我已经为 Usercontrol 中的所有子控件设置了 HorizontalAlignment 和 VerticalAlignment 属性。什么都没有改变!
这是用户控件 XAML
<Usercontrol
x:Class="Circles.CustomControls.Control"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Circles.CustomControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="700" Height="700">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Canvas x:Name="Container" Background="Transparent" Width="700" Height="700" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Rectangle x:Name="Card" Stroke="Black" Width="700" Height="700" Fill="White" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Canvas>
</Grid>
</UserControl>
这是用户控件的代码隐藏
public sealed partial class Control : Usercontrol
{
public Control()
{
this.InitializeComponent();
this.Height = 700;
this.Width = 700;
}
}
我希望当开发人员将用户控件放到页面上时,会出现一个大小为 700x700 的用户控件。
更新 1 这是一些图片
Image1 - This shows the issue with the bounding rectangle
Image2 - This show the DatePicker control
用户控件和日期选择器控件都以相同的方式添加到页面。
- 从工具箱中选择控件并将其拖到页面上。
Image1 是用户控件
- 较小的矩形 100x100
- 用户控件和画布的控件大小均设置为 700x700
- 画布尺寸显示为 700x700
- VS 属性窗口显示 100x100
- VS 页面 XAML 将高度和宽度显示为 100x100
Image2 是日期选择器
- 边界矩形遵循内部控件的可见轮廓
- VS 属性窗口设置了默认大小
@Nico Zhu - MSFT 和@Faenrig - 我希望这能说明我的问题。如果你所做的事情是有效的,那么我很想知道我做错了什么或者没有做什么????
【问题讨论】:
-
为什么Control构造函数中没有
InitializeComponent();? -
抱歉,我的复制粘贴编辑错误
-
我检查了您的屏幕,为什么您将
TargetAirRiFle2宽度设置为100在网格中的哪个位置?