-1

I am working on a Silverlight/XNA game. Having structure like this :

  • My GamePlay class is inherited from InGamePage.
  • Where InGamePage is inherited from PhoneApplicationPage.
  • InGamePage has a OnLayoutUpdated method to render SL controls(using UIElementRenderer ).

This is as per SL/XNA code sample

Everything is working fine till I decided to create a textblock in gamepage.xaml . I want that textBlock to show the some static game variables( like distance covered by hero).

Now where should I write this line :

debugTextBlock.Text = GameData.data.distanceCovered; 

so that textblock shows the current values. (I tried to hook a LayoutUpdate but its throwing Application_UnhandledException saying "Layout cycle detected. Layout could not complete.")

Any hint/link is highly appreciated.

Priyank
  • 145
  • 1
  • 2
  • 11
  • What is the exception that is being thrown? – Rowland Shaw Jul 03 '12 at 12:43
  • @Rowland edited the question, well the exception is ("Layout cycle detected. Layout could not complete.") – Priyank Jul 04 '12 at 05:57
  • Did you see [this earlier question](http://stackoverflow.com/q/636245/50447)? – Rowland Shaw Jul 04 '12 at 07:56
  • that didn't helped much @Rowland, I guess its SL+XNA that's resisting two controls to render simultaneously. Because if I try to update the debugTextBlock.Text on any event its working fine. – Priyank Jul 04 '12 at 10:23
  • It would help if you explained where you are trying to set the text from -- if it's from your overridden `OnLayoutUpdated` I could understand that you're trying to change something during render (which could change the positions of a bunch of other things) - you've already spotted that if you change where you update the text, it'll work, so that sounds like your solution. – Rowland Shaw Jul 04 '12 at 11:33
  • Ok let me make this more clear. In my SL+XNA game SL controls are drawn using UIElementRenderer and XNA game using spritebatch. Now I want my game variables to be drawn on a scroll-able textblock which shows me current values. Right now values are updated only when I tap on the textblock(as i assign text on the gotfocus event.) – Priyank Jul 05 '12 at 05:14

1 Answers1

0

I think that simply using Dispatcher might work:

Dispatcher.BeginInvoke(()=>
{
debugTextBlock.Text = GameData.data.distanceCovered; 
});
Skiba
  • 440
  • 1
  • 6
  • 17
  • sorry if I am sounding novice but where should is perform this code. I check tried this thread also (http://stackoverflow.com/questions/9320181/multiple-asynchronous-ui-updates-in-silverlight) but all vain. – Priyank Jul 04 '12 at 06:00
  • Since you provided Exception beeing thrown my answer does not match your problem at all. Is debugTextBlock fixed size or it changes size accordingly to content inside? – Skiba Jul 04 '12 at 11:28