經過漫長的搜索,我發現這個: 如果我以正確的方式理解你,你想在運行時使用xaml在WPF中創建用戶定義的窗體。 我不確定但是,我認爲資源文件不會幫助你,因爲所有的xaml表單都是在程序集中預編譯的。我發現了一些可能聽起來像是解決問題的方法。它被稱爲Sattalite大會。在第一步中,您必須創建一個新的資源文件。第二步是將其與彙編鏈接器(Al.exe)鏈接。形式.net框架。 MSDN Creating Satellite Assemblies
第一步在運行時創建一個的resourcefile(這裏一點幫助)
public static void CreateResourceFile()
{
string resourceFileName = "externeresource";
System.Xml.XmlDocument xmldoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader("/runtimeWPForm.xml");
reader.WhitespaceHandling = WhitespaceHandling.None;
xmldoc.Load(reader);
ResourceWriter resourceWriter = new ResourceWriter(resourceFileName);
/*Add XmlDocument must be Serializable to store it in
resourceWriter.AddResource("xamlgrid", xmldoc.ToString());
the Resource, so i stored a String here. (not testet)*/
resourceWriter.Close();
MessageBox.Show("File " + resourceFileName + " created");
reader.Close();
}
第二步從資源文件中創建一個Sattlelite大會與議會鏈接Al.exe工具
最後一步是加載從Sattalite大會(這裏一點幫助)
Uri GridUri = new Uri(/*Note1*/, UriKind.Relative);
Windows.Resources.StreamResourceInfo sri = Application.GetResourceStream(GridUri);
System.Windows.Markup.XamlReader xrdr = new System.Windows.Markup.XamlReader();
Grid grd = (Grid)xrdr.LoadAsync(sri.Stream);
this.Content = grd;
注1 XAML形式: 資源文件 - 參照的文CED裝配Pack URIs in WPF
Uri uri = new Uri("/ReferencedAssembly;component/ResourceFile.xaml",UriKind.Relative);
這裏,因爲我認爲Construct XAML Forms at Runtime with Resource Files
這是所有我發現你和functionallity不能保證一些有用的信息。 我感興趣,如果這將適用於你,所以請發送成功的答案或如果你解決了你的問題。
PS .:如果這個工程我認爲你只需要重新啓動你的主應用程序來加載新的sattalite程序集。也許你必須啓動一個完成這項工作的ohter應用程序,並在完成後再次自動啓動你的主應用程序。
Best regouards GatewayToCode