This project is read-only.

How to update UI text.

Oct 13, 2010 at 10:55 PM

Hi just stared to look at implementing Nuclex to help elevate the hell that is XNA's default menu and text input systems but I'm having trouble working out how to update text on a window after its been created, for example


        private void InitializeComponent(Game1 main)
            this.helloWorldLabel = new Nuclex.UserInterface.Controls.LabelControl();
            // helloWorldLabel
            this.helloWorldLabel.Text = main.someFloat.ToString();
            this.helloWorldLabel.Bounds = new UniRectangle(10.0f, 15.0f, 110.0f, 30.0f);


[test is a value that changes via the main Update() method]

I always get a "0" in the UI box.

I'm assuming that I've either just overlooked something simple but cant think what it is or there's a function somewhere that allows me to do this that I haven't found [and hopefully not that its impossible to do]

Any help would be appreciated.

[just a little note I've also tried using  "main.someString"]


Oct 13, 2010 at 11:08 PM


The Nuclex GUI follows a very simple design, so there's no data binding like in WinForms/WPF and you'll have to update your label's text yourself when the value changes.

For example, you could give your Window class a property to set the value:

  public string HelloWorldText {
    get { return this.helloWorldLabel.Text; }
    set { this.helloWorldLabel.Text = value; }

Then you can update the text in Game1.Update(), or wherever you need it, like this:

  public override void Update(GameTime gameTime) {
    this.myWindow.HelloWorldText = this.someFloat.ToString();

    // ...other stuff...

That also lets you avoid referencing the Game1 class inside the window (it helps a bit with structure avoiding this kind of reference in larger games, if you feel it's the best way in your case, go ahead :D)

Oct 13, 2010 at 11:23 PM
Edited Oct 13, 2010 at 11:23 PM

awsome thanks. just a quick follow up is there anyway to gain access to a menu directly from the gui [for example using code from the demos]

after this 

mainScreen.Desktop.Children.Add(new DemoDialog( ));


is there any way of accessing


or is the only option


    public class Game1 : Microsoft.Xna.Framework.Game
        DemoDialog dd; protected override void Initialize() { dd = new DemoDialog( ); mainScreen.Desktop.Children.Add(dd); } protected override void Update(GameTime gameTime) { dd.HelloWorldText = selected.e.ToString(); }

which is fine, just wondering as my attempts failed


Jan 3, 2011 at 9:44 PM
Edited Jan 3, 2011 at 9:44 PM

Hi, I'm new at this framework.

Could you explain me how to appear that LabelControl at screen?

I'm doing this:

protected override void Initialize()
     this.gui = new GuiManager(Services);
     Viewport viewport = GraphicsDevice.Viewport;
     Screen mainScreen = new Screen(
viewport.Width, viewport.Height);
      this.gui.Screen = mainScreen;

    LabelControl labelControl = new LabelControl("text");
    labelControl.Bounds = new UniRectangle(10.0f,
 15.0f, 30.0f, 30.0f);

Thank you.