Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - How to access method declared in App.xaml.cs?

Tags:

c#

wpf

How can I access, using C#, a public instance method declared in App.xaml.cs?

like image 311
Gus Cavalcanti Avatar asked Oct 22 '09 18:10

Gus Cavalcanti


People also ask

How can I access a control in WPF from another class or window?

Access of the controls from within the same assembly is hence allowed. If you want to access a control on a wpf form from another assembly you have to use the modifier attribute x:FieldModifier="public" or use the method proposed by Jean.

What is app XAML CS?

xaml. cs is the code-behind page for MainPage. xaml. It's where you add your app logic and event handlers. Together these two files define a new class called MainPage , which inherits from Page, in the HelloWorld namespace.

How do I add apps to XAML to WPF project?

Solution 1Go to add new items -> online templates and then choose 'Silverlight Application Class'. This will add a new app. xaml for you.


2 Answers

((App)Application.Current).YourMethod .... 
like image 88
Akash Kava Avatar answered Oct 11 '22 01:10

Akash Kava


Have you considered to create a separate class to hold your application wide methods (eg. AppState.cs)?

like image 22
thomasmartinsen Avatar answered Oct 11 '22 00:10

thomasmartinsen