How to bind to a "x:static" resource in code-behind in WPF
wpf
Solution
`x:Static` just resolves a `static` member for you, so you can write as:
var binding = new Binding("ApplicationLanguage");
binding.Source = Application.Current;
That said, I don't follow why you think you need to do this in code.
Problem
For some user controls, I have this binding: ``` AppLanguage="{Binding Path=ApplicationLanguage, Source={x:Static Application.Current}}" ``` This works for controls that are declared/instantiated in XAML. However, I have a control that is only instantiated dynamically (it won't be used regularly, so I don't want an instance (up to 3, actually) to gobble up memory for nothing all the time. Now, unless I'm missing something, I have to declare my bindings in code-behind. That works fine when I have an easy one (ElementName + Path), but in the above case, I can't figure out how to write it in code-behind. Of course, in this particular case, the control could simply refer to My.Application.ApplicationLanguage, but trying to do this got me curious anyway. I did a good number of searches and couldn't find anything similar (might be my search keywords though. :))