Introduce the XAML method in the background code

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.