Alex
Alex

Reputation: 11147

can't render the buttons on the entire display in SLXNA

I have a SLXNA game and am trying to display a menu on the SL part. The problem is that the buttons seem to display but not entirely. In a certain part of the screen the buttons just stop to be drawn(i can see tje button till a point where it looks like it gets 'cut off'). What could be the problem?

note: the app is in landscape and is a default SL/XNA template

here is the code(i will only display the code that interests us):

XAML :

    </Grid.RowDefinitions>

    <!-- Toggles the visibility of the ColorPanel -->
    <Button VerticalAlignment="Top"   BorderBrush="DarkRed" Foreground="DarkRed" Margin="1,0,-1,0">pause</Button>
    <Button VerticalAlignment="Bottom"  BorderBrush="DarkRed" Foreground="DarkRed" Margin="1,0,-1,0">change</Button>

    <!-- Arrange buttons in a horizontal line by using StackPanel -->

</Grid>

i declare :

UIElementRenderer elementRenderer;

public GamePage()
        {
           //  some typical code.....

            LayoutUpdated += new EventHandler(GamePage_LayoutUpdated);
        }


void GamePage_LayoutUpdated(object sender, EventArgs e)
        {
            // Create the UIElementRenderer to draw the XAML page to a texture.

            // Check for 0 because when we navigate away the LayoutUpdate event
            // is raised but ActualWidth and ActualHeight will be 0 in that case.
            if (ActualWidth > 0 && ActualHeight > 0 && elementRenderer == null)
            {

                elementRenderer = new UIElementRenderer(this, (int)ActualWidth, (int)ActualHeight);
            }
        }

 private void OnDraw(object sender, GameTimerEventArgs e)
        {
            SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.LightGoldenrodYellow);

           // draw some 3d objects

            elementRenderer.Render();

            spriteBatch.Begin();
            spriteBatch.Draw(elementRenderer.Texture, Vector2.Zero, Color.White);

            spriteBatch.End();


            // TODO: Add your drawing code here
        }

Upvotes: 1

Views: 327

Answers (1)

Paul Annetts
Paul Annetts

Reputation: 9604

I've seen this before. I think the problem here is that because your page is Landscape it actually gets created first by Silverlight as Portrait and then "rotated" around - leaving your UIElementRenderer with the wrong size and everything looking wrong.

Try recreating your UIElementRenderer in response to the OrientationChanged event. (i.e. call the code you have in the GamePage_LayoutUpdated method again)

Upvotes: 1

Related Questions