Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the Application object inside a Window class in WPF?

Tags:

c#

.net

wpf

Can we access the current System.Windows.Application object inside a Window class in WPF ?

like image 346
Brij Avatar asked Jun 13 '13 15:06

Brij


People also ask

What is an application class in WPF?

All applications tend to share a common set of functionality that applies to application implementation and management. This topic provides an overview of the functionality in the Application class for creating and managing applications. In WPF, common application-scoped functionality is encapsulated in the Application class.

How to access controls in another WPF form?

To access controls in another WPF forms, you have to declare that control as public. The default declaration for controls in WPF is public, but you can specify it with this code: And after that you can search in all active windows in the application to find windows that have control like this:

What is a window in WPF?

In WPF, a window is encapsulated by the Window class that you use to do the following: Display a window. Configure the size, position, and appearance of a window. Host application-specific content. Manage the lifetime of a window. The following figure illustrates the constituent parts of a window:

What is the use of code behind file in WPF?

This allows the code-behind file to be associated with the partial class that is generated for the markup file when the application is built, for more information, see Compile a WPF Application. In code-behind, the Window class must implement a constructor that calls the InitializeComponent method.


2 Answers

Yes sure. You can access it everywhere in a WPF application.

// assuming that you derivate of Application is named App ((App)Application.Current).SomePropertyOfApp = ... 
like image 74
DHN Avatar answered Sep 19 '22 12:09

DHN


Yes - it's as easy as Application.Current.

like image 25
JeffRSon Avatar answered Sep 21 '22 12:09

JeffRSon