我为SingleSinstance应用程序创建了一些逻辑,必须使用自己的入口点(不是app.xaml)进行应用程序。我在app.xaml中有一些样式,现在不起作用。在我的情况下,如何将我的app.xaML的这些资源计算用于整个项目?

我的班级管理应用程序启动

 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();
    }
}

和我自己的入口点:

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

和我的app.xaml代码后面:

    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();
    }
}

我的app.xaml有一些代码,这些代码可减少不起作用的资源。为什么?

有帮助吗?

解决方案

我找到了解决这个问题的解决方案。我创建了新的资源词典,并在这个新词典中粘贴了我所有的其他资源:

<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>

然后只是对我的app.cs进行了一些编辑

   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();
    }
}

我希望这个解决方案可以帮助某人)))

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top