473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XAML - Storing and accessing global constants - How?

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
Feb 9 '08 #1
2 9802
Dan,

Take a look at this blog entry from Karsten Januszewski:

http://blogs.msdn.com/karstenj/archi...15/439167.aspx

It addresses how to access constants in XAML.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DanThMan" <da******@cox.netwrote in message
news:3b**********************************@e4g2000h sg.googlegroups.com...
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

Feb 11 '08 #2
On Feb 11, 9:13 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Dan,

Take a look at this blog entry from Karsten Januszewski:

http://blogs.msdn.com/karstenj/archi...15/439167.aspx

It addresses how to access constants in XAML.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"DanThMan" <danth...@cox.netwrote in message

news:3b**********************************@e4g2000h sg.googlegroups.com...
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
Perfect! Thank you!

-Dan
Feb 11 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Leigh Riley | last post by:
Hi, Can someone tell me if the following is possible? I have a file containing some STATIC variables, and some functions e.g. -------------------------------------------------...
10
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
20
by: 2obvious | last post by:
I've been trying to create read-only global variables by creating constants (Const) in my global.asa, but I can't seem to reference them. Sticking them in an include works fine, but it seems more...
25
by: Daniel Bass | last post by:
how do i declare a global variable in c#.net? it's like it want's everything in classes... there are times when globals are good, like having constants in a program which apply to several...
4
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be...
8
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger...
5
by: Demetri | last post by:
Unfortunately, where I work it is forbidden to use stored procedures. I know, I know...it's pretty stupid. But I can not change that. Anyway, currently we have our sql stored in an embedded resx...
1
by: dnn | last post by:
How can I access dynamically loaded variables? I am trying to load an external javascript file dynamically and then access its variables. The script is loaded by the onload handler. The code...
6
by: lazy | last post by:
hi, I have some constants defined in a php script say config.php. I want to use the variables there defined in other scripts. couple of questions regd that: 1. Is there an alternative to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.