kajovajo
kajovajo

Reputation: 211

c# class for constants bindable in xaml as well as in code

I would like to have a class with constant strings, like for example here and here. But I would like to be able to bind to these values in xaml as well as in code, e.g.:

<Window x:Class="Ccompany.Product.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lex="http://wpflocalizeextension.codeplex.com"
        lex:ResxLocalizationProvider.DefaultAssembly="<-- would like to be able to insert the constant here -->"                
        >

Could you please also provide an example of how to bind the proposed 'constants class' solution in xaml as well?

Note: I tried different things before posting, tried to wrap the constant into a property but I was still unable to bind it in xaml.

Upvotes: 2

Views: 416

Answers (1)

Dan
Dan

Reputation: 9847

Why not just this?:

{x:Static ns:TypeName.ConstValue}

This will work for constant values like the following:

public class TypeName
{
    public const int ConstValue = 5;
}

Upvotes: 2

Related Questions