Frage

Ich habe eine Logik für die SingleInInstance -Anwendung erstellt und muss meinen eigenen Einstiegspunkt (nicht App.xaml) für die Anwendung verwenden. Ich habe einige Stile in app.xaml, die jetzt nicht funktionieren. Wie kann ich diese Ressourcen aus meiner App.xaml für das gesamte Projekt in meiner Situation verwenden?

Meine Klasse zum Verwalten von Anwendungsstarts

 public class SingleInstanceManager : WindowsFormsApplicationBase
{
    App app;

    public SingleInstanceManager()
    {
        this.IsSingleInstance = true;
    }

    protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
    {
        try
        {
            // First time app is launched
            app = new App();
            App.Current.Properties["rcID"] = e.CommandLine;
            //IntroLibrary.OpenDocumentFromNotify();
            app.Run();
            return false;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return false;
        }
    }

    protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
    {
        // Subsequent launches
        base.OnStartupNextInstance(eventArgs);
        Intro win = (Intro)app.MainWindow;
        if (eventArgs != null)
        {
            App.Current.Properties["rcID"] = eventArgs.CommandLine[0];
        }
        IntroLibrary.OpenDocumentFromNotify();
        app.Activate();
    }
}

und mein eigener Einstiegspunkt:

    public class EntryPoint
{
    [STAThread]
    public static void Main(string[] args)
    {
        SingleInstanceManager manager = new SingleInstanceManager();
        manager.Run(args);
    }
}

Und mein App.xaml -Code dahinter:

    public partial class App : Application
{
    protected override void OnStartup(System.Windows.StartupEventArgs e)
    {
        base.OnStartup(e);

        // Create and show the application's main window
        Intro window = new Intro();
        window.Show();
    }

    public void Activate()
    {
        // Reactivate application's main window
        this.MainWindow.Activate();
    }
}

Und mein App.xaml hat einen Code, der die Ressourcenkrankheiten verringern, was nicht funktioniert. Wieso den?

War es hilfreich?

Lösung

Ich fand eine Lösung für dieses Problem. Ich erstelle ein neues Ressourcenwörterbuch und füge alle meine anderen Ressourcen in diesem neuen Wörterbuch ein:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="themes/ShinyBlue.xaml" />
    <ResourceDictionary Source="themes/Anim.xaml" />
    <ResourceDictionary Source="themes/Generic.xaml" />
    <ResourceDictionary Source="themes/CustomStyles.xaml" />
    <ResourceDictionary Source="themes/Resource.xaml" />
    <ResourceDictionary Source="themes/CustomWindowChrome.xaml" />
 </ResourceDictionary.MergedDictionaries>

Und dann habe ich einfach ein bisschen meine App.cs bearbeitet

   public partial class App : Application
{

    protected override void OnStartup(System.Windows.StartupEventArgs e)
    {
        base.OnStartup(e);
        ResourceDictionary rd = new ResourceDictionary() { Source = new Uri("CommonStyle.xaml",UriKind.RelativeOrAbsolute) };
        this.Resources = rd;
        // Create and show the application's main window
        Intro window = new Intro();
        window.Show();
    }

    public void Activate()
    {
        // Reactivate application's main window
        this.MainWindow.Activate();
    }
}

Ich hoffe diese Lösung hilft jemandem))))

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top