簡體   English   中英

使用WPF Prism MVVM的Visual Studio C#加載項

[英]Visual Studio C# Add-In with WPF Prism MVVM

我試圖為UI創建一個Visual Studio加載項,我決定使用Prism庫實現Model View ViewModel模式。 只要您獨立啟動項目,它就可以正常工作。 將其插入到外接程序項目中后,出現以下異常:“文件或程序集“ Prism.Wpf,PublicKeyToken = 91a96d2a154366d8”或未找到其依賴項之一。系統找不到文件。

所有參考均已更新,所有內容都在一個項目中。

在此處輸入圖片說明

在Connect.cs中,我只希望顯示主窗口。

public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
    {
        handled = false;
        if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
        {
            if(commandName == "SynopticGeneratorAddIn.Connect.SynopticGeneratorAddIn")
            {
                handled = true;
                ShowMainWindow();
                return;
            }
        }
    }

    private void ShowMainWindow()
    {
        AutomaticSynopticGenerationCore.Views.MainWindow mainWindow = new AutomaticSynopticGenerationCore.Views.MainWindow();
        mainWindow.Show();
    }

由於沒有人給出答案,所以我告訴您我是如何做到的。 我將其重寫為VSPackage,因為加載項被認為已過時。 它沒有幫助。 同時更新所有程序包也無濟於事。 起作用的一件事是在創建Window實例之前使用Prism。 這是一個丑陋的解決方法,所以如果您有更好的東西,請告訴我。

    /// <summary>
    /// This function is the callback used to execute a command when the a menu item is clicked.
    /// See the Initialize method to see how the menu item is associated to this function using
    /// the OleMenuCommandService service and the MenuCommand class.
    /// </summary>
    private void MenuItemCallback(object sender, EventArgs e)
    {           
        LoadPrism();
        AutomaticSynopticGenerationCore.Views.MainWindow mainWindow = new AutomaticSynopticGenerationCore.Views.MainWindow();
        mainWindow.Show();
    }

    /// <summary>
    /// Loads Prism from own attached Assembly before window instance gets created
    /// </summary>
    static void LoadPrism()
    {            
        typeof(Prism.Bootstrapper).ToString();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM