---
title: "Variables which need to be live across the application in WPF"  
description: "Variables which need to be live across the application in WPF"  
author: "Royce Roy"  
published: 2014-03-06  
updated: 2014-03-06  
canonical: https://www.mindstick.com/forum/1979/variables-which-need-to-be-live-across-the-application-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# Variables which need to be live across the application in WPF

I am developing a [WPF](https://www.mindstick.com/forum/304/wpf) application. I need some [variables](https://www.mindstick.com/articles/715/php-variables)/information not to destroy until [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) closes that application. Which [method](https://www.mindstick.com/forum/166/webservice-method) is best? [Static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) [Class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) with static variables? Moreover what is the best [practice](https://yourviews.mindstick.com/story/1498/terrific-benefits-of-a-morning-meditation-practice) in this [scenario](https://yourviews.mindstick.com/view/81221/sports-will-change-the-education-scenario)?

## Replies

### Reply by Pravesh Singh

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"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:globals="clr-namespace:MyNamespace">

</Window>


---

Original Source: https://www.mindstick.com/forum/1979/variables-which-need-to-be-live-across-the-application-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
