2

I want the user to select one out of many elements.

So I'm creating a long list of StringElement, each one with a specific caption. Each element is associated with a specific value. My ideas was to set the Value property of the StringElement. However, this makes the value being shown on the right side of the element.

How can I hide this value? I only need it when the user tapped an entry.

poupou
  • 43,413
  • 6
  • 77
  • 174
Krumelur
  • 32,180
  • 27
  • 124
  • 263

1 Answers1

2

Except for the most basic settings-like dialog I end up (90% of the time) defining my own Element types. It solves many issues (like this one) and reduce duplicated code.

So you get something like:

class MyStringElement : StringElement {
  public MyStringElement (string caption, string hiddenValue) : base (caption) {
      HiddenValue = hiddenValue;
  }

  public string HiddenValue { get; set; }
}

You might also want to use the caption as the key to (an existing?) Dictionary<string,string> to reduce the memory requirement of each element (depending on how long your list turns out to be). In any case having your own Element type makes it easier to change its storage/behaviour in the future (with minimal impact elsewhere in your code).

poupou
  • 43,413
  • 6
  • 77
  • 174