Reputation: 155
Im creating a UWP app. In the App I have created a Usercontrol that has a rectangle of a set size inside it. The size is 700x700. I have also set the Usercontrol to 700x700.
How I thought it would work is that when the developer places the Usercontrol onto the Page then a Usercontrol will appear with a size of 700x700.
However the Usercontrol is appearing with a size of 100x100!
This is the code from the Page after I double-clicked the Usercontrol in the Toolbar to add it to the Page.
<Custom:Control HorizontalAlignment="Left" Height="100" Margin="254,158,0,0" VerticalAlignment="Top" Width="100"/>
Note the Height and Width are 100x100!
I have set the Height and Width properties of the Usercontrol to 700x700 in the XAML and the class constructor. Nothing changes!
I have set the set the HorizontalAlignment and VerticalAlignment properties for all the Child controls in the Usercontrol. Nothing changes!
This is the Usercontrol 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>
This is the Usercontrol code-behind
public sealed partial class Control : Usercontrol
{
public Control()
{
this.InitializeComponent();
this.Height = 700;
this.Width = 700;
}
}
I expect that when a developer places the Usercontrol onto the Page then a Usercontrol of size 700x700 will appear.
UPDATE 1 Here are some pictures
Image1 - This shows the issue with the bounding rectangle
Image2 - This show the DatePicker control
Both a Usercontrol and a Datepicker control where added to the Page in the same way.
Image1 is the Usercontrol
Image2 is the Datepicker
@Nico Zhu - MSFT and @Faenrig - I hope this illustrates my issue. If what you have done is working then I would love to know what I have done wrong or am not doing 😁
Upvotes: 0
Views: 607
Reputation: 32775
How to get the Usercontrol to keep its size once put on the Page?
The size of Usercontrol
will be constrained by it's parent container. if the parent size was limited to 100*100, Your Usercontrol
will be resized. so please edit the parent container.
<StackPanel Orientation="Vertical" Height="700" Width="700">
<local:CustomLabel/>
</StackPanel>
Upvotes: 1