This article introduces three methodsCodeDynamic Loading XAML , There are two ways to load existing XAML File, one way is to include XAML Code string WPF .
I wrote RegEx experience, WPF Program provides more flexibility.
I, In the resource dictionary, load XAML File
Application. Current. Resources. mergeddictionaries. insert (0,
Application. loadcomponent (New uri ("ABC/index. XAML ",
Urikind. Relative) as resourcedictionary );
This method is only applicable toXAMLResource file. If you load resources other than the project in the test, the system will prompt that the file cannot be found.
2. Load External data into the resource dictionary XAML File
Application. Current. Resources. mergeddictionaries. insert (0,
Xamlreader. Load (New filestream ("C: \ index. XAML", filemode. Open)
Resourcedictionary );
This method is applicableXAMLResource file.
Iii. Change XAML Format String to object
Xamlreader. parse (@ "<flowdocument
Xmlns = "" http://schemas.microsoft.com/winfx/2006/xaml/presentation "> <Paragraph> <run> Hi! </Run> </Paragraph> </flowdocument> ")
As flowdocument
This method generates a stream Document Object, in RegEx , I use this method to flexibly control the document content to generate processing results.
note that, this method requires . net 3.5 SP1 supported, load method overload.
Dynamic Loading XAML File technology is suitable for loading resources to implement language switching, theme conversion, and other functions.
DYNAMIC CONVERSION XAML The string is WPF Object technology can provide more flexible object generation methods for programs, which is particularly useful in some complex situations.
Download the PDF version of this article: http://www.box.net/shared/y2ajdmgrvl