2

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.

Community
  • 1
  • 1
kajovajo
  • 211
  • 3
  • 12
  • 1
    `I tried different things before posting` Show exactly what you tried and why it didn't work. – tnw Jul 09 '13 at 15:08

1 Answers1

2

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;
}
Dan
  • 9,717
  • 4
  • 47
  • 65
  • Constants.cs: `namespace Company.Product.Common.Constants { public class Constants2 { public const string DefaultAssembly = "value"; } }`. MainWindow.xaml: `` produces: The name "Constants2" does not exist in the namespace "clr-namespace:Company.Product.Common.Constants". – kajovajo Jul 09 '13 at 15:45
  • Today I created an empty (new) project, tried your solution and it worked. There must have been something wrong with the project in which I tried it before. I remember I tried to clean/rebuild even restart Visual Studio - without success. I'd like to apologize for my mistake. Your answer is actually a correct one. Thank you. – kajovajo Jul 20 '13 at 08:06