locked
How to align the border as center inside the popup control

    Question

  • I am trying to align the border to the center of the popup. But it aligns only at the top left corner. can anyone suggest how to align the border to the center of the popup control.

    I am using .Net framework 4.5.1 and WIRNT application.

     <Grid Name="MainGrid" Background="Green">
        <Popup Name="mainpopup" IsOpen="True"  >
                <Border Name="MainBorder" Background="LightBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="400" Width="1300">
    
                </Border>
        </Popup>
    </Grid>
    

    Additional Details: In My application (winrt application) the border height is set as Auto it takes the height according to its contents height.

    thanks in advance.


    Ravi Shankar_B


    • Edited by Ravi Shankar_B Thursday, March 20, 2014 7:53 AM additional details
    • Moved by Mike Danes Thursday, March 20, 2014 7:57 AM WinStore app
    Thursday, March 20, 2014 7:51 AM

Answers

  • the popup class fits to the size of his content. so what you can do:

    <Grid Name="MainGrid" Background="Green" SizeChanged="MainGrid_SizeChanged">
            <Popup Name="mainpopup" IsOpen="True">
                <Grid x:Name="FullSize">
                    <Border Name="MainBorder" Background="LightBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="400" Width="1300">
    
                    </Border>
                </Grid>
            </Popup>
        </Grid>

    and in c#:

    private void MainGrid_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                FullSize.Width = MainGrid.ActualWidth;
                FullSize.Height = MainGrid.ActualHeight;
            }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, March 20, 2014 10:23 AM