2012-01-26 58 views
1

我有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 
     } 
+0

有幾個問題:您在此處使用了什麼屏幕方向 - 您是否允許方向動態更改?您是否使用標準SL/XNA模板項目來設置SharedGraphicsDeviceManager? –

+0

@PaulAnnetts我使用的是標準的SL/XNA模板,但方向只是風景 – Alex

回答

1

我以前見過這個。我認爲這裏的問題是,因爲你的頁面是橫向的,它實際上首先由Silverlight作爲肖像創建,然後「旋轉」 - 留下UIElementRenderer錯誤的大小和一切看起來錯誤。

嘗試重新創建您的UIElementRenderer以響應OrientationChanged事件。 (即再次調用您在GamePage_LayoutUpdated方法中的代碼)

+0

我爲方向添加了一個事件處理程序,並再次調用代碼,但沒有奏效。我設法通過在elementRenderer = new UIElementRenderer(this,(int)ActualWidth,(int)ActualHeight)中反轉ActualHeight和ActualWidth來修復它。代碼。謝謝! – Alex