2

Is that seriously NOT possible? I have solutions to bind one-way to properties in static classes and certainly i have solutions to bind two-way to static properties in non-static classes... but...

I mean, the workaround is easy, i can just make my static class to a singleton with a static instance getter (see here), but isn't there a proper way??

my class looks something like that:

public static class TestClass
{
  public static string TestProp {get; set;}
}

And now please assume that i properly implement INotifyPropertyChanged in the "normal" way in the setter (omitted for simplicity).

How should the XAML look like to bind two-way to this property? Thanks.

Martin Booka Weser
  • 3,192
  • 5
  • 28
  • 41

1 Answers1

-1

this answer may help: wpf static binding question or this: Binding to static class property

in short, your case would look something like:

{Binding Source={x:Static whatever:TestClass.TestProperty}, Path=.}
Community
  • 1
  • 1
dtm
  • 794
  • 5
  • 15
  • 2
    i think this doesn't work for two way binding - though i have no time to test now. I will test it tomorrow. – Martin Booka Weser Oct 25 '12 at 17:46
  • This throws the exception "Two-way binding requires Path or XPath." Thus it is not an answer to my question :( – Martin Booka Weser Oct 29 '12 at 10:14
  • fixed the Path. sorry about that. by the way, how do you do property-changed notification in a static class? – dtm Oct 29 '12 at 15:52
  • 2
    well, actually i needed to change the value only in the gui, so i didn't implement the property-changed. Which, now when you ask, would be not so easy as well. However, your fix (Path=.) lets the project compile, but still, the changes made in the gui are not reflected in my data... – Martin Booka Weser Nov 06 '12 at 19:33