# Mixing XNA and Silverlight gives wierd graphics

I making a small 3dgame which is made as a Silverlight and XNA app, but when I draw the sprites the graphics becomes all wierd.

All my primitive types are rendered correctly, but my 3d models are just wierd

My Draw is like this when silverlight is set to draw

private void OnDraw(object sender, GameTimerEventArgs e)
{
// Render the Silverlight controls using the UIElementRenderer
elementRenderer.Render();

// Clear the screen to a solid color
SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue);

switch (gameState)
{
case GameState.ChooseStarter:
TextBlockStatus.Text = "Find Starting Player";
break;
case GameState.PlaceBrick:
TextBlockPlayer.Text = (playerTurn == PlayerTurn.PlayerOne) ? "Player One" : "Player Two";
TextBlockState.Text = "Place Brick";
foreach (IGraphicObject obj in _3dObjects)
{
obj.Draw(cameraPosition, e);
}
break;
case GameState.GiveBrick:
TextBlockState.Text = "Give Brick";
break;
}

spriteBatch.Begin();
// Using the texture from the UIElementRenderer,
// draw the Silverlight controls to the screen
spriteBatch.Draw(elementRenderer.Texture, cameraProjection, Color.White);
spriteBatch.End();
}


This gives me this output

If I comment the spritebatch lines out I get the correct output, except the silverlight text is of course not shown

I am not entirely sure what to look for except that zero vector I am giving to the spritebatch, but if thats the source I have no idea what I am supposed to set it as epspecially when its a 2d vector

• That worked cool :) that line just isnt in the demo project from msdn :/ – Mech0z Apr 7 '12 at 18:02

That's actually something that SpriteBatch does and you need to restore it manually. See this link for more information on the problem, as it also covers all the other device states that are also changed by SpriteBatch.
In this particular example, in order to reenable the depth buffer, just add the following line to the end of your OnDraw method:
GraphicsDevice.DepthStencilState = DepthStencilState.Default;