在 WPF 的 UserControl 中调整控件大小

Sizing controls in UserControl in WPF

我有一个用户控件并在 window

中使用这个用户控件
<UserControl x:Class="WpfApplication12.UserControl1"
       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" 
             xmlns:local="clr-namespace:WpfApplication12"
             mc:Ignorable="d"  Width="300"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid Background="White">
        <Ellipse x:Name="Ellipse1"
                Margin="-700,150,-700,-150"
                Fill="Black" Visibility="Visible"
                Height="1600"
                Width="1800" 
                StrokeThickness="5"
                Stroke="Transparent"/>
    </Grid>
</UserControl>
<Window
    x:Class="WpfApplication12.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:WpfApplication12"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="525"
    Height="350" 
    mc:Ignorable="d">
    <Grid x:Name="Grid1">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF333333" Offset="0"/>
                <GradientStop Color="#FF1E1E1E" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
        <local:UserControl1 Margin="50" />
    </Grid>
</Window>

结果:

我想删除红色矩形。想要一种方法来删除这些矩形,以便应该显示的最大值是其父控件内的圆圈。

我更改了我的代码并开始工作,我将 Grid 更改为 StackPanel,并进行了修复,

      <Grid Background="White">
                <Ellipse x:Name="Ellipse1"
                        Margin="-700,150,-700,-150"
                        Fill="Black" Visibility="Visible"
                        Height="1600"
                        Width="1800" 
                        StrokeThickness="5"
                        Stroke="Transparent"/>
            </Grid>
    To:
<StackPanel Background="White">
        <Ellipse x:Name="Ellipse1"
                Margin="-700,150,-700,-150"
                Fill="Black" Visibility="Visible"
                Height="1600"
                Width="1800" 
                StrokeThickness="5"
                Stroke="Transparent"/>
    </Grid>