XAML - Storing and accessing global constants - How?

D

DanThMan

This seems like it should be so simple, but I'm just not having much
luck with this. I have an constant in my App.xaml.cs file (i.e., code-
behind) called Name.

public const string Name = "Dan";

And now, I want a Label on my Window1.xaml page that shows the Name. I
will eventually want to show the same Name on other pages. So, I want
to be able to access (bind to?) this global constant from anywhere in
the project.

I've read up on x:Static, static resources, and different ways of
binding data to XAML properties, but so far, no combination of these
techniques seems to work. What is the best way to store and access
constants in XAML that apply to the whole project?

Thanks for you help,

-Dan
 
D

DanThMan

Dan,

Take a look at this blog entry from Karsten Januszewski:

http://blogs.msdn.com/karstenj/archive/2005/07/15/439167.aspx

It addresses how to access constants in XAML.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


This seems like it should be so simple, but I'm just not having much
luck with this. I have an constant in my App.xaml.cs file (i.e., code-
behind) called Name.
public const string Name = "Dan";
And now, I want a Label on my Window1.xaml page that shows the Name. I
will eventually want to show the same Name on other pages. So, I want
to be able to access (bind to?) this global constant from anywhere in
the project.
I've read up on x:Static, static resources, and different ways of
binding data to XAML properties, but so far, no combination of these
techniques seems to work. What is the best way to store and access
constants in XAML that apply to the whole project?
Thanks for you help,

Perfect! Thank you!

-Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top