c# - Instantiate ResourceDictionary xaml from other Assembly -
I have defined a Reource dictionary containing a WPF class library called Color and Brush, BrushResources.xaml. <> I want to use some brush code from another assembly, which refers to this library project. How to get an example of What are you asking is a component of the necessary functionality to provide true skinning in an application . Receiving resources from a different assembly involves reading compiled XAM or joining the other assembly. Here is a method that I use in a skinning library to recover BAM from an assembly: Then, To change, you do the following: and to merge into another assembly from an existing assembly: pre & lt; ResourceDictionary xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" & gt; & Lt; There are so many colors and brushes & gt; & Lt; / ResourceDictionary & gt;
ResourceDictionary ?
// relevant namespace: // System.Windows.Baml2006; // Using System.Xaml; Public static list & lt; Stream & gt; GetBamlStreams (assembly name skinASSandname) {list & lt; Stream & gt; BamlStreams = New list & lt; Stream & gt; (); Assembly skin assembly = assembly Load (skin assembly); String [] resourceDictionaries = skinAssembly.GetManifestResourceNames (); Foreign words (name in string resource resource resources) {ManifestResourceInfo info = skinAssembly.GetManifestResourceInfo (resourceName); If (info.ResourceLocation = ResourceLocation.ContainedInAnotherAssembly!) {Stream resourceStream = skinAssembly.GetManifestResourceStream (ResourceName); (ResourceReader Reader = New Resource Reader) (foreach (Online entry entry in Reader) {// TODO: It is a resource tool that I consider / key about RD (brush resources. ) If the IRC is the relevant resource (Entry)) {bamlStreams.Add (value as the entry stream);}}}}} Return Bamstream;}
// If .NET 3.5, this initialization is required: Type xamlType = typeof (System.Windows.Markup.XamlReader); // LoadBam-method = xamlType.GetMethod (LOAD_BAML_METHOD, BindingFlag nonpolic | Public static tee loadbamal & lt; T & gt; (stream stream) {// for .NET 3.5: // parsercontent parser consensing = new parsertext (); // object [] parameters = new object [] {Stream, parser kontax, tap, false}; // object bamal root = loadmb meth. Quoc (empty, parameter); // Return (t) Bamal root; // for .NET 4.0 var Reader = New Bamal 2006 reader (stream); Var Author = New XamlObjectWriter (reader.SchemaContext); While (reader.Read ()) author. Wightnet (Reader); Return (T) Writer result; }
Private zero load resources () {list & lt; Stream & gt; BamlStreams = GetBamlStreams (full name); Forcha (stream stream in Bamstream) {ResourceDictionary RD = Loadbaml & lt; Resource & gt; (Stream); This example works in a very common way for scanning purposes, but you can simplify it to meet your specific goal. Important With some examples of displaying you can see a skinning library using this method.
Comments
Post a Comment