XAML - Storing and accessing global constants - How?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DanThMan

    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
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: XAML - Storing and accessing global constants - How?

    Dan,

    Take a look at this blog entry from Karsten Januszewski:



    It addresses how to access constants in XAML.


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

    "DanThMan" <danthman@cox.n etwrote in message
    news:3b3e7dcb-f849-4089-b656-4dedbb411b4f@e4 g2000hsg.google groups.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

    Comment

    • DanThMan

      #3
      Re: XAML - Storing and accessing global constants - How?

      On Feb 11, 9:13 am, "Nicholas Paldino [.NET/C# MVP]"
      <m...@spam.guar d.caspershouse. comwrote:
      Dan,
      >
      Take a look at this blog entry from Karsten Januszewski:
      >

      >
      It addresses how to access constants in XAML.
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - m...@spam.guard .caspershouse.c om
      >
      "DanThMan" <danth...@cox.n etwrote in message
      >
      news:3b3e7dcb-f849-4089-b656-4dedbb411b4f@e4 g2000hsg.google groups.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

      Comment

      Working...