wpf - Merging dictionaries into multiple user controls - does this affect memory? -


i have ui project containing (so far) 18 xaml resources, merged app.xaml so:-

<application ...>    <application.resources>        <resourcedictionary>            <resourcedictionary.mergeddictionaries>                <resourcedictionary source="pack://application:,,,/foo.client.common;component/uistyles/colours.xaml" />                <resourcedictionary source="pack://application:,,,/foo.client.common;component/uistyles/buttons.xaml" />                <resourcedictionary source="pack://application:,,,/foo.client.common;component/uistyles/menus.xaml" />                // etc..            </resourcedictionary.mergeddictionaries>        </resourcedictionary>    </application.resources> </application> 

when edit of xaml views in project intellisense (resharper) on style names contained in these resources.

now, application implements "plug-in" architecture, , there several class library projects containing views , view models; these dynamically loaded @ runtime. although application runs fine, don't style name intellisense when edit xaml views in these projects. can intellisense work merging necessary styles view's xaml, e.g.:-

<usercontrol.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="pack://application:,,,/foo.client.common;component/uistyles/buttons.xaml" />             //etc..         </resourcedictionary.mergeddictionaries>          // user control-specific styles go here.     </resourcedictionary> </usercontrol.resources> 

by doing in each user control, "duplicating" each resource , therefore bloating application's memory requirements? if so, there way around it? if created resource file in class library, merged 15 "core" resources that, merged 1 resource views? still result in same issue?

failing guess i'll have keep "merge xaml" commented out in each view, , temporarily reinstate when need work on view.

good question. have same problem.

there 2 problems here:

1) annoying duplication in xaml code - not talking duplication of actual resources - rather, have write <resourcedictionary> everywhere.

2) actual duplication of resources - wasting resources, plus: lose benefit of swapping out styles on runtime, if not placed in same place.

how can solve these problems?

by creating new xaml file, calling sharedresourcedictionary.xaml, includes resources. included app.xaml.

this allow pull resourcedictionary inside other xaml components, in short way, include sharedresourcedictionary.xaml.

the second trick make sure resources created once:

[assembly: xmlnsdefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation",  "wpftutorial.utils")]  /// <summary> /// shared resource dictionary specialized resource dictionary /// loads content once. if second instance same source /// created, merges resources cache. /// </summary> public class sharedresourcedictionary : resourcedictionary {     /// <summary>     /// internal cache of loaded dictionaries      /// </summary>     public static dictionary<uri, resourcedictionary> _shareddictionaries =         new dictionary<uri, resourcedictionary>();      /// <summary>     /// local member of source uri     /// </summary>     private uri _sourceuri;      /// <summary>     /// gets or sets uniform resource identifier (uri) load resources from.     /// </summary>     public new uri source     {         { return _sourceuri; }         set         {             _sourceuri = value;              if (!_shareddictionaries.containskey(value))             {                 // if dictionary not yet loaded, load setting                 // source of base class                 base.source = value;                  // add cache                 _shareddictionaries.add(value, this);             }             else             {                 // if dictionary loaded, cache                 mergeddictionaries.add(_shareddictionaries[value]);             }         }     } } 

if doesn't work, there's comments below: http://www.wpftutorial.net/mergeddictionaryperformance.html

it's possible explore land of xaml ifdef code:

does xaml have conditional compiler directive debug mode?


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -