Binding const member in code behind from xaml in WPF Binding const member in code behind from xaml in WPF wpf wpf

Binding const member in code behind from xaml in WPF


You would be better off using the StaticExtension, like so:

Uid="{x:Static local:YourClass.ID_foo}"

Where local is an xmlns alias for the C# namespace of your class. More information can be found here.

The problem with using Binding is you are adding a lot overhead for something that will never change. The binding will attempt to monitor your property. Also, there are known "leaks" with using a Binding with a non-dependency property on an object that don't implement INotifyPropertyChanged.


You need to make a property that returns the constant (defined in a const), ie:

private const string ID_Foo = "foo";public string FooId{   get { return ID_Foo; }}

Once this is in a property, it will be usable via binding.