在WPF中的UserControl中调整控件大小

时间:2016-02-09 14:26:26

标签: wpf xaml silverlight

我有一个用户控件并在窗口中使用此usercontrol

<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>

结果:

enter image description here

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

1 个答案:

答案 0 :(得分:1)

我改变了我的代码并且工作了,我将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>
相关问题