我有一个SLXNA游戏,我正试图在SL部分显示菜单。问题是按钮似乎显示但不完全。在屏幕的某个部分,按钮只是停止绘制(我可以看到按钮直到它看起来像'被切断'的点)。可能是什么问题呢?
注意:该应用是横向的,是默认的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
}
答案 0 :(得分:1)
我之前见过这个。我认为这里的问题是因为你的页面是Landscape,它实际上首先由Silverlight创建为Portrait,然后“旋转” - 让你的UIElementRenderer
大小错误,一切都看错了。
尝试重新设置UIElementRenderer
以响应OrientationChanged
事件。 (即再次调用GamePage_LayoutUpdated
方法中的代码)