locked
chagne the location of a button

    Question

  • how do i change the location of the button (x,y) in vs 2013 for windows 8.1 apps? since btn.location dosen work anymore...
    Sunday, February 23, 2014 4:58 PM

Answers

  • That sounds like a great use for a Grid:

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Button Grid.Row="0" Grid.Column="0" />
                <Button Grid.Row="0" Grid.Column="1" />
                <Button Grid.Row="0" Grid.Column="2" />
                <Button Grid.Row="1" Grid.Column="0" />
                <Button Grid.Row="1" Grid.Column="1" />
                <Button Grid.Row="1" Grid.Column="2" />
                <Button Grid.Row="2" Grid.Column="0" />
                <Button Grid.Row="2" Grid.Column="1" />
                <Button Grid.Row="2" Grid.Column="2" />
            </Grid>

    You'll obviously want to flesh out the details, but that should give the right basic structure

    --Rob

    Thursday, February 27, 2014 2:07 AM
    Owner

All replies

  • The location is controlled by the container, and where it draws by its RenderTransform.

    Generally the best way is to use structured layout controls such as Grids and put the Button in a Row, Column location rather than to try to explicitly place it. Explicit placement tends to cause problems with different screen sizes and resolutions.

    See Quickstart: Adding layout controls

    Explain your scenario in more detail if you need more specific advice.

    --Rob

    Sunday, February 23, 2014 5:37 PM
    Owner
  • In windows App location property does exits you can change location of button like

     btn.Arrange(New Rect(cellOrigin.X, cellOrigin.Y, dw, dh))
    Visit link below for more information

    http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.uielement.arrange(v=vs.105).aspx


    Ashish Pandey

    Sunday, February 23, 2014 5:44 PM
  • Arrange doesn't let the app set a control's the location explicitly. It is part of the layout system to let the container controls position their children.

    You also linked Windows Phone docs which aren't relevant to Windows Store apps, although the layout system is similar.

    --Rob

    Sunday, February 23, 2014 5:50 PM
    Owner
  • I have an array of buttons and i want to arrange them like a 9x9 grid each button in the same size.
    Tuesday, February 25, 2014 7:05 AM
  • That sounds like a great use for a Grid:

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Button Grid.Row="0" Grid.Column="0" />
                <Button Grid.Row="0" Grid.Column="1" />
                <Button Grid.Row="0" Grid.Column="2" />
                <Button Grid.Row="1" Grid.Column="0" />
                <Button Grid.Row="1" Grid.Column="1" />
                <Button Grid.Row="1" Grid.Column="2" />
                <Button Grid.Row="2" Grid.Column="0" />
                <Button Grid.Row="2" Grid.Column="1" />
                <Button Grid.Row="2" Grid.Column="2" />
            </Grid>

    You'll obviously want to flesh out the details, but that should give the right basic structure

    --Rob

    Thursday, February 27, 2014 2:07 AM
    Owner