c# - WPF: Give a ResourceDictionary a Name -


i have got resourcedictionary full of pathgeometry's icons, possible can give resourcedictionary name can use c# view of icons, , make things more grouped together?

so use 1 of pathgeometry's example

app.current.resources.icons["refresh1"] geometry  or  app.current.resources["icons"]["refresh1"] geometry 

currently use app.current.resources["refresh1"] geometry use 1 of pathgeometry's.

edit: unclear why is, well, unclear. poster below understood question unclear in reason wanting this. reason isn't required, want answer i'm asking, not discussion on why want this.

this 1 of straightforward questions people spend more time arguing answering! :) people can argue merit of as once start doing things dynamically loading resourcedictionaries (say, external plugin dlls) topics become relevant indeed!

to answer question, yes, of course possible. main caveat here if add resourcedictionaries application resources dictionary xaml compiler confused you're trying do. trick here explicitly specify single top-level resourcedictionary , add resources, including key'd resourcedictionaries, content of that:

<application.resources>      <resourcedictionary xmlns:sys="clr-namespace:system;assembly=mscorlib">          <resourcedictionary x:key="dictionary1">             <sys:string x:key="str1a">string 1a</sys:string>             <sys:string x:key="str1b">string 1b</sys:string>             <sys:string x:key="str1c">string 1c</sys:string>         </resourcedictionary>          <resourcedictionary x:key="dictionary2">             <sys:string x:key="str2a">string 2a</sys:string>             <sys:string x:key="str2b">string 2b</sys:string>             <sys:string x:key="str2c">string 2c</sys:string>         </resourcedictionary>          <!-- other application resources go here -->      </resourcedictionary>  </application.resources> 

here's xaml statically binds dictionaries show method works intended:

<stackpanel>     <listbox itemssource="{staticresource dictionary1}" displaymemberpath="value" />     <listbox itemssource="{staticresource dictionary2}" displaymemberpath="value" /> </stackpanel> 

result:

enter image description here

if want access resources in code you'll need cast first array lookup resourcedictionary, index actual item key:

var str = (app.current.resources["dictionary1"] resourcedictionary)["str1a"].tostring(); 

if that's messy can clean helper class so:

public class global {     static global _global = new global();     public static global dictionaries { { return _global; } }      public resourcedictionary this[string index]     {         { return app.current.resources[index] resourcedictionary; }     } } 

which use this:

var str = (string)global.dictionaries["dictionary1"]["str1a"]; 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -