質問

SingleInstanceアプリケーション用にいくつかのロジックを作成し、アプリケーションに独自のエントリポイント(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