Home > DeveloperSection > Forums > Variables which need to be live across the application in WPF
Royce Roy
Royce Roy

Total Post:134

Posted on    March-06-2014 11:00 PM


 1 Reply(s)
 821  View(s)
Rate this:
I am developing a WPF application. I need some variables/information not to destroy until user closes that application. Which method is best? Static Class with static variables? Moreover what is the best practice in this scenario?

Pravesh Singh

Total Post:411

Posted on    March-06-2014 11:16 PM

Hi Royce,

You can also create static class and reference it in xaml like this:

namespace MyNamespace


    public static class Globals


        public static double SomeVariable { get { return 1.0; } }



Then access it from xaml like this:

<UserControl Width="{x:Static globals:Globals.SomeVariable}" />

where globals is defined at top top of your xaml like following:

<Window x:Class="MyNamespace.MainWindow"





Don't want to miss updates? Please click the below button!

Follow MindStick