Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 472.2k

How to align a button within a rectangle in wpf ui?

Jun 13 2024 5:49 AM

Hi Team

I have a button and want to align it so it does not affect the margins of other properties within my grid. It must inside the rectangle not outside the rectangle, sot it does not affect the position of the margins of labels and textbox. Please assist me in this below logic in xml code.

`<Rectangle HorizontalAlignment="Left" Height="257" Stroke="#FFCFCFD1" VerticalAlignment="Top" Width="260" Margin="14,104,0,0"/>
<!---Recipe Details-->
        <Label Content="Recipe Details" FontWeight="SemiBold"  HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalAlignment="Top" Width="260" BorderBrush="#FFBEBEBE" Background="#FFE3E3E3" BorderThickness="1.5" Foreground="Black" Height="30" VerticalContentAlignment="Center" FontSize="12" Margin="14,103,0,0"/>
        <Label x:Name="lblIDX" FontWeight="SemiBold" FontSize="10" Visibility="Visible" Content="IDX:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="124" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,135,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <TextBox x:Name="txtIDX" Foreground="Black" HorizontalAlignment="Left" Visibility="Visible" FontSize="10" Height="26" Margin="146,132,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Label x:Name="lblRecipe" FontSize="10" FontWeight="SemiBold" Visibility="Visible" Content="Recipe Name:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="124" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,163,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <TextBox x:Name="txtRecipe" Foreground="Black" FontSize="10" HorizontalAlignment="Left" Visibility="Visible" Height="26" Margin="146,160,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Label x:Name="lblRecoNo" FontSize="10" FontWeight="SemiBold" Visibility="Visible" Content="Rec No:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="124" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,191,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <TextBox x:Name="txtRecNo" FontSize="10" Foreground="Black" HorizontalAlignment="Left" Visibility="Visible" Height="26" Margin="146,188,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Label x:Name="lblDesc" FontSize="10" FontWeight="SemiBold" Visibility="Visible" Content="Description:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="124" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,220,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <TextBox x:Name="txtDescription" FontSize="10" Foreground="Black" HorizontalAlignment="Left" Visibility="Visible" Height="26" Margin="146,217,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Label x:Name="lblBatchSize" FontSize="10" FontWeight="SemiBold" Visibility="Visible" Content="Batch Size:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="124" HorizontalContentAlignment="Right" Background="#FFE3E3E3" Margin="17,248,0,0" BorderThickness="1" BorderBrush="#FFBEBEBE"/>
        <TextBox x:Name="txtBatchSize" FontSize="10" Foreground="Black" HorizontalAlignment="Left" Visibility="Visible" Height="26" Margin="146,245,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>

        <Grid Margin="17,248,0,0">
            <Button x:Name="btnAdd_Save" Content="Save" Click="btnAdd_Click"  Background="ForestGreen" BorderBrush="ForestGreen" FontWeight="SemiBold" Visibility="Visible" HorizontalAlignment="Left" Margin="176,415,0,0" VerticalAlignment="Top" Width="90" />
        </Grid>`

 


Answers (1)