Silverlight (1) Get objects defined in generic. XAML or other *. XAML

Source: Internet
Author: User
Runtime Environment: Silverlight 3.0 ( I did not perform tests under 2.0. It seems that this method does not support 2.0, because resourcedictionary does not have the source attribute under 2.0)

Resourcedictionary Resources =   New Resourcedictionary ();
Resources. Source =   New Uri ( " /Cinlap. UI. SL. controls; component/themes/generic. XAML " , System. urikind. Relative );

Controltemplate=Resources [templatename]AsControltemplate;

As long as the resourcedictionary. Source attribute is set to a suitable Uri, you can use the key to obtain the desired object.

Added: Another scenario using resourcedictionary was just found.
When creating a custom control, we may need. defining the styles of multiple controls in XAML makes it very difficult to find out more definitions. If it is defined in a single file, it is then defined in generic. it is not good to include data in XAML. You can see telerik. redcontrol for Silverlight used <? Include (***. XAML)?> But I have no idea how to implement this function. Instead, I had to find another method. Finally, I found that the same function can be implemented using resourcedictionary. Source.CodeAs follows:

< Resourcedictionary
Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml" >

<Resourcedictionary. mergeddictionaries>
<ResourcedictionarySource= "/Cinlap. UI. SL. controls; component/themes/dockpanel. XAML"/>
</Resourcedictionary. mergeddictionaries>
</Resourcedictionary>

Obviously, this method is also used to include another XAML file in a XAML file.

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.