UWP - Dynamically load different Styles.xaml -


is possible dynamically load different style resourcedictionary @ run time depending on condition?

i want have single build of app have different colours/branding depending on specific setting. assuming above isn't possible best achieve this?

resourcedictionary cannot set dynamically @ runtime far remember - not on uwp. imho way change colorbrushes or whole styles.

first option: if need change colors dynamically, need create brush within resourcedictionary

<solidcolorbrush x:key="mybrush">#333344</solidcolorbrush> 

and use styles/xaml layouts , on.

to change need (assuming have 1 resource distionary set or 1 containing color brushes first) take brush dictionary , replace color.

if (application.current.resources.mergeddictionaries[0].containskey("mybrush")) {     var brush = application.current.resources.mergeddictionaries[0]["mybrush"] solidcolorbrush;     if (brush != null)     {         brush.color = return new color() { = 255, r = r, g = g, b = b };     } } 

second option: if need change whole style @ runtime (assuming have mystyle , myotherstyle set within resource dictionaries, , want apply control named mycontrol):

 switch(anyvalue)  {      case 1:           var mystyle = application.current.resources["mystyle"] style;           if(mystyle != null)           {               mycontrol.style = mystyle;                            }           break;      case 2:           var myotherstyle = application.current.resources["myotherstyle"] style;           if(myotherstyle != null)           {               mycontrol.style = myotherstyle;                             }           break; } 

third option: change style visualstates set control. need write own visualstates controls want change , switching beetwen them manually. never tried don't know how reliable way be. looks best way in case of performance (assumption only) keeping visualstates hand every control may need implement own visualstatemanager , may cause trouble keeping right visualstate @ time want it.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -