1

I have this XAML code and I want the grid to be in row 2 and Column 1-3.
Now the problem is if I specify the margin of grid, it doesn't look good with devices of different sizes and if I don't specify margin, the grid goes out of the mobile screen.

How to keep the margin auto and grid inside the layout

<Grid Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3">
    <Button x:Name="undoButton" 
            Content="undo" 
            Grid.Column="1" Grid.Row="2"
            HorizontalAlignment="Left" 
            Click="undoButton_Click" Height="70" Width="90" 
            FontSize="16" Background="#FF4B9599" />
    <Button x:Name="redoButton" Content="redo" 
            Height="70" 
            Width="90"
            Grid.Column="2" Grid.Row="2"
            HorizontalAlignment="Center"  
            Click="redoButton_Click"  FontSize="16" 
            Background="#FF4B9599"/>
    <Button x:Name="clearButton" 
            Content="clear" 
            HorizontalAlignment="Right" 
            Height="70" Width="90"
            Grid.Column="3" Grid.Row="2"
            FontSize="16"  Background="#FF4B9599" 
            Click="clearButton_Click"/>
</Grid>

Here is the definition of rows and columns:

<Grid.RowDefinitions>
    <RowDefinition Height="90" />
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

There is the grid if I don't add margin

enter image description here

4
  • didn't Understand your question, can you be more specific.Please include some drawings for the expected result.
    – Joseph
    Apr 15, 2015 at 12:18
  • @Joseph please check the screenshot now I hope it is clear
    – Saira
    Apr 15, 2015 at 12:33
  • What other elements you have inside the Grid? Apr 15, 2015 at 12:38
  • try changing HorizontalAlignment="Right" for undoButton and HorizontalAlignment="Left" for clearButton.
    – Joseph
    Apr 15, 2015 at 12:40

2 Answers 2

1

From what you have provided us, the solution would be pretty simple

Replace this:

<Grid.RowDefinitions>
    <RowDefinition Height="90" />
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

with this:

<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="*"/>
    <RowDefinition Height="90" />
</Grid.RowDefinitions>

If you give us more information of the desired result and the other items you want to put in row 0 and row 1, we can give more specific help to you.

2
  • No it doesn't Work. but I appreciate the help Thank you :)
    – Saira
    Apr 15, 2015 at 13:42
  • * , '9*' & '*' worked. before I did not knew how it works but now I understand it.
    – Saira
    Apr 15, 2015 at 16:25
-1

I don't know what the problem was or where it was but this worked

 <RowDefinition Height="Auto" MinHeight="80"/>
 <RowDefinition Height="*"/>
 <RowDefinition Height="Auto" MinHeight="70" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.