Mohammad Bigdeli
Mohammad Bigdeli

Reputation: 127

Sizing controls in UserControl in WPF

I have a user control and use this usercontrol in 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>

And result:

enter image description here

I want to remove the red Rectangles. Want a way to remove these rectangles such that the maximum that should be displayed is the circle inside its parent control.

Upvotes: 2

Views: 88

Answers (1)

Mohammad Bigdeli
Mohammad Bigdeli

Reputation: 127

I change my code and worked, I change Grid to StackPanel, and Fixed,

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

Upvotes: 1

Related Questions