0

Only in the System.Console do I get the result, it print the number of characters that are left, and it update it

So whats wrong, how do i update it in the Element?

Hope you guys can help me with this.

Console:

Characters typed(left): in Value it should write the number of characters that are left. enter image description here

     var root = new RootElement ("Send Message");

        var messageElement = new MultilineEntryElement ("", "0123456789") 
        {
            Editable = true,
            Height = 120
        };
        var messageSection = new Section ();

        int leangtOfChar = 200 - messageElement.Value.Length;




        var lengthElement = new StringElement ("characters typed:", leangtOfChar.ToString());

        messageElement.Changed += delegate {

            System.Console.WriteLine (leangtOfChar.ToString ());

            //lengthElement.Value = (leangtOfChar.ToString());

        };



        root.Add(messageSection);
MemoDreamer
  • 103
  • 8

1 Answers1

1

The problem is that when you update a normal StringElement it doesn't automatically update the attached cell.

To force an update for just that cell, I would recommend either:

  • calling root.Reload(lengthElement, UITableViewRowAnimation.Fade) after you change the value
  • or using a custom element/cell type instead of StringElement - basically you could model this on the simple code in BooleanElement - but use a UILabel as the accessory instead of a UISwitch.

If you wanted to go further - to actually allow StringElement to be updated without a reload - then you can do this by modifying the Element class to track whether a cell instance is currently attached. I've done exactly that in a databinding branch of monotouch.dialog - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross.Dialog/Dialog/Elements/Element.cs - but this is almost certainly overkill for what you are trying to do right now.

Stuart
  • 66,722
  • 7
  • 114
  • 165