TextBlock doesn't update

Hi

Would anybody explain why in following block of code the text value of TextBlock is diplayed only once without any further updading? It’s simple code to display system clock value.


            Glide.FitToScreen = true;

            string xml;
            xml = "<Glide Version=\"" + Glide.Version + "\">";
            xml += "<Window Name=\"window\" Width=\"320\" Height=\"240\" BackColor=\"FFFFFF\">";
            xml += "</Window>";
            xml += "</Glide>";
            Window window = GlideLoader.LoadWindow(xml);

            TextBlock lbl = new TextBlock("label", 255, 20, 20, 100, 50);

            window.AddChild(lbl);

            new Thread(delegate()
            {
                while (true)
                {
                    DateTime dt = DateTime.Now;

                    string hour = (dt.Hour < 10) ? "0" + dt.Hour.ToString() : dt.Hour.ToString();
                    string minute = (dt.Minute < 10) ? "0" + dt.Minute.ToString() : dt.Minute.ToString();
                    string second = (dt.Second < 10) ? "0" + dt.Second.ToString() : dt.Second.ToString();
                    string result = hour + ":" + minute + ":" + second;

                    lbl.Text = result;

                    Thread.Sleep(1000);
                }
            }
            ).Start();

            Glide.MainWindow = window;

            Thread.Sleep(Timeout.Infinite);

You need to use Dispatcher in this case. Search the forum.

Dispatcher.BeginInvoke(() => { 
                lbl.Text = result;
            });

Which Dispatcher??? Application dispatcher? Doesn’t work at all.


    public class Program : Application
    {
        public static void Main()
        {
            new Program().Run();
        }

        protected override void OnStartup(EventArgs e)
        {
            Glide.FitToScreen = true;

            string xml;
            xml = "<Glide Version=\"" + Glide.Version + "\">";
            xml += "<Window Name=\"window\" Width=\"320\" Height=\"240\" BackColor=\"FFFFFF\">";
            xml += "</Window>";
            xml += "</Glide>";
            Window window = GlideLoader.LoadWindow(xml);

            TextBlock lbl = new TextBlock("label", 255, 20, 20, 100, 20);
            window.AddChild(lbl);

            Dispatcher d = this.Dispatcher;

            new Thread(delegate()
            {
                while (true)
                {
                    DateTime dt = DateTime.Now;

                    string hour = (dt.Hour < 10) ? "0" + dt.Hour.ToString() : dt.Hour.ToString();
                    string minute = (dt.Minute < 10) ? "0" + dt.Minute.ToString() : dt.Minute.ToString();
                    string second = (dt.Second < 10) ? "0" + dt.Second.ToString() : dt.Second.ToString();
                    string result = hour + ":" + minute + ":" + second;

                    d.BeginInvoke(delegate(object arg)
                    {
                        {
                            lbl.Text = result;
                            return null;
                        }
                    }, null);

                    Thread.Sleep(1000);
                }
            }
            ).Start();

            Glide.MainWindow = window;

            Thread.Sleep(Timeout.Infinite);
        }
    }

Hmm… I have to try it later tonight. Did you try to call Render after you changed the property?

Yes. No effect.

lbl.Text = result;
window.FillRect(lbl.Rect);
lbl.Invalidate();

lbl.Text = result;
window.FillRect(lbl.Rect);
lbl.Invalidate();

It would be better to incapsulate this in the TextBlock.Text property, 'cause it’s not obvious for users and it’s not good that to simply change text value we have to do 2 additional calls.

Smth like that:


public string Text
    {
        get
        {
            return this._text;
        }
        set
        {
            this._text = value;
            parentWindow.FillRect(this.Rect);
            this.Invalidate();
        }
    }

Gothic:

I am really looking forward to seeing your graphics library!

Will you be releasing a beta version so we can all evaluate it and make lots of comments?

Mike

I have already made a bunch of controls but they all are based on netmf wpf. Although they look greatly they still are quiet slow. In some UI scenarios they can’t be used for a great sorrow.
That’s why I looked into Glide/Pyxis/Gadgetos direction and tried testing them. There are a lot of issues with them as you already saw in the adjacent topic and their speed isn’t good so far. So I decided to port my own UI controls library that I made for XNA 3D games some years ago. It also uses rendering to bitmap approach (like all games do), but the difference between it and Glide/Gadgetos is HOW this rendering is performed. I did porting of a little part of it, just few controls, tested and you see it performs about 10 times faster then mentioned libraries.
It will take some time to get a beta version. But one thing is obvious - we still don’t have an acceptable gui library for netmf so far. And I personnaly need such a library as well for my projects. So the work will go on. :slight_smile:

I have to disagree… I have used Glide and I am beginning to look at at Clix, and they both are acceptable to me.

I used Glide to develop a GUI which had 120 controls that were updated dynamically. It took under ten seconds to create the GUI, and then updating was fast enough not to noticeable.

Embedded programming is about trade-offs. If you want super fast graphics, then a library may be too much overhead. Sometimes you have to creative and reasonable.

My getting familiar with these libraries began from simple situation with form, panel and 3 labels displaying system time. All libs failed. Can you imagine how I was surprised and disappointed!!! Especialy knowing the Glide price is about 1000$ for commercial usage. I was almost down :slight_smile:

You ran your Glide test with assumptions. I tested what you explained and it worked. Looking at the documentation for the TextBlock you’d see the code necessary to update the text.

http://www.ghielectronics.com/downloads/Glide/Library%20V%201.0.3/html/1ef24de6-c32c-eb27-d70d-3fa6ec9f9358.htm

The FillRect/Invalidate code was left out of the Text property purposely. Giving the user ultimate control. For example, if an object is on a window that is not the MainWindow, it does not need to be rendered until the window is shown. Putting that code inside the Text property would have it overwrite the current MainWindow inappropriately.

Agree, but it could be checked right in Text property setter (if parent == MainWindow…, or if parent.visible…), no? Is it ok that user should care is or not window visible or main window? It seems it should be handled inside the control automatically. Else we could transfer a half of our work to the users.

I’ve been following this discussion with greate interest. I think that Gothic has made some very valid points, especially regarding performance. I’m very hopeful that the result of this discussion is that the libraries from GHI and from Skewworks will end up being as fast as they can possibly be.

However, I disagree with Gothic regarding how much functionality should be encapsulated into the graphic library and how much should be left up to the application developer.

In my experience it is always a bad idea to try to make a library too smart. The best libraries that I have ever used have always been very lean, and very flexible… allowing the developer maximum control over how and when things are done.

And for all reasons above, Glide ships with complete source code. In embedded systems, there is no answer for all this discussion. We can discuss it for days and endup nowhere. You want it more flexible? You want it faster? Faster in what area? Need less ram usage? more ram? Application specific?

The goal from glide? It is a graphics library with window designer and has everything a professional needs to create a slick user interface in minutes. Will it fit every need? no and no other library will :slight_smile: Is there room for improvement? Yes there is and there will ALWAYS be. This is software, there is always version ++ :slight_smile:

This discussion was very healthy and I am sure we all will benefit from it but it is time to go back and concentrate on making new things instead of discussing every line in code.

@ jasdev
Thank you! :slight_smile: You are completely right, we have to know the edge where to stop else we could end up with paranoia and endless process like code fore code. I simply mean about text property that comparing for example to the big .net, its label class text property doesn’t make us to care is our parent window visible or not, active or not, minimized or not - all this is handled inside the label class. If we as developers and users of .NET framework should care about such things it would be kind of hell though :slight_smile:
I meant just that and no more.

@ Gus
Thank you for participation in this discussion. And you’re right. Such discussions are to make us go forward and do not stop with our achievements. There is always a space for improvements and growth.

Let’s wish good luck to each other and good collaboration! :wink:

It´s not clear to me, what i need to do to update the textbox?

protected void btn1_TapEvent(object sender)
{
txtMatricula = (TextBox)window.GetChildByName(“txtMatricula”);
txtMatricula.Text = “111111111111”;
}

You have to call Invalidate. See example from Josh earlier in this thread.

But, where are the code of invalidate()? It´s a native code of netmf or ghi?

TextBox should have Invalidate method. You can also invalidate whole Window.

If you have doubts you can also check Glide’s source code at:

http://netmfglide.codeplex.com/