Autor Beitrag
mannyk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 83
Erhaltene Danke: 1



BeitragVerfasst: Mi 16.03.11 13:57 
Hallo,

ich habe ein WPF Projekt angelegt und dafür werden ja zwei Xaml-Komponenten angelegt.
Zum einen die App.xaml (Einstiegspunkt) und das Hauptfenster Window.xaml.

Nun meine Frage: Ich muss beim Programmstart ein paar Initialisierungen vornehmen, die unabhängig vom Hauptfenster Window.xaml(.cs) sind. Kann ich diese in App.xaml.cs vornehemen? Wenn ja, wie?
Der einzige Code hier ist:
ausblenden C#-Quelltext
1:
2:
3:
4:
    public partial class App : Application
    {

    }

In der App.xaml steht folgendes:
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
<Application
    x:Class="TestProject.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>
IsNull
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 97
Erhaltene Danke: 11


VS 2010, C#, AHK
BeitragVerfasst: Fr 18.03.11 15:56 
Ja, so ist es vorgesehen. Du registrierst den Startup-Event und fügst dort deine eigene Logik ein:

ins app xaml: StartUp="Application_Startup"
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
<Application
    x:Class="TestProject.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartUp="Application_Startup"
    StartupUri="Window.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>


und in deinem App.xaml.cs:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        void Application_Startup(object sender, StartupEventArgs e){
            // your custom init code
        }
    }

Für diesen Beitrag haben gedankt: mannyk
mannyk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 83
Erhaltene Danke: 1



BeitragVerfasst: Fr 18.03.11 16:05 
Danke, perfekt