1

I would like to bind a textbox to a property of a static class. I would like this to be two-way binding. My static class is this (trimmed):

public static class ocrVar
{
    static ocrVar()
    {  
        MeterNumber = new Element();
    }
}

The Element class looks like this (trimmed):

public class Element
    {

        public List<string> Value { get; set; }

        public Element()
            : this(new List<string>())
        {
        }
        public Element(List<string> value)
        {
        Value = value;
        }
    }

If I want to take a TextBox and bind it to ocrVar.MeterNumber.Value[0], is there a way to do that?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Ben Walker
  • 2,037
  • 5
  • 34
  • 56
  • Please read [Writing the perfect question](http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx), specifically **Sample code and data**. It's good that you include a sample of your code, but please keep it as short as possible. – Patrick Sep 13 '12 at 20:31

1 Answers1

0

Since it's static class , and you want to perform two-way binding, you have supply the path and provide a class is not static as a trick and use the binding

in your case, would be

<Window.Resources>
    <local:ocrVar x:Key="ocrVarManager"/>
</Window.Resources>

<TextBox Text="{Binding Source={StaticResource ocrVarManager}, Path=MeterNumber.Value[0]}"/>

you can refer to Binding to Static Property

Community
  • 1
  • 1
Turbot
  • 5,095
  • 1
  • 22
  • 30