我有SLXNA遊戲,並試圖在SL部件上顯示菜單。問題是按鈕似乎顯示,但不完全。在屏幕的某個部分,按鈕只是停止繪製(我可以看到按鈕直到它看起來像被切斷的點)。可能是什麼問題呢?無法渲染SLXNA中整個顯示器上的按鈕
注:該應用程序是在景觀,是一個默認的SL/XNA模板
這裏是代碼(我將只顯示我們感興趣的代碼):
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>
我宣佈:
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
}
有幾個問題:您在此處使用了什麼屏幕方向 - 您是否允許方向動態更改?您是否使用標準SL/XNA模板項目來設置SharedGraphicsDeviceManager? –
@PaulAnnetts我使用的是標準的SL/XNA模板,但方向只是風景 – Alex