c# - What is the simplest way to apply themeing -


let's have resourcedictionary with:

update:

<solidcolorbrush x:key="aquabrush" color="#257d8e"/>   <solidcolorbrush x:key="greenbrush" color="green"/> 

lets app: enter image description here

i have combobox items (aqua, green , gray) when select aqua button, should display this: enter image description here , button , other control want set should update background aqua too.

how can bind splitview , button , other control's background 1 property , when select "aqua" use "aquabrush" , when select "green", use "greenbrush"?

thanks.

since have solidcolorbrush resource defined in xaml, can code behind changing background color based on conditions @ runtime :

if(some condition){     relativepanelname.background = (solidcolorbrush)resources["navpanebackgroundbrushblue"]; }else {     relativepanelname.background = (solidcolorbrush)resources["navpanebackgroundbrushgreen"]; } 

hope helps..!


edit :

additionally, not can define static resources of own, can use system's theme resources .

for example can access system's accent color :

c#

var color = (color)this.resources["systemaccentcolor"]; 

xaml

<grid.background>    <solidcolorbrush color="{staticresource systemaccentcolor}"/> </grid.background> 

edit 2 : since question has been changed , framed in better way pretty clear want know application wide theme-ing . can application wide theme-ing in multiple ways,so here's 1 :

  • define application resource in app.xaml available through out application .

    enter image description here

  • now these resources available through out pages.you can access them :

enter image description here

this way have app-wide theme.

you can access application resources code behind :

gridname.background=new solidcolorbrush((color)application.current.resources["colorthree"]); 

edit 3 :

in app.xaml :

<resourcedictionary>             <color x:key="themecolor">#f4425f</color>             <solidcolorbrush x:key="useraccentbrush" color="{staticresource themecolor}"/> </resourcedictionary> 

on click of button change color of "useraccentbrush" , reflected in controls use brush..

private void button_click(object sender, routedeventargs e) {     var brush = (solidcolorbrush)application.current.resources["useraccentbrush"];              if (cb.selectedindex != -1)             {                 switch (cb.selectedindex)                 {                     case 0:                         brush.color = color.fromargb(255, 242, 101, 34);                         break;                      case 1:                         brush.color = color.fromargb(255, 232, 10, 90);                         break;                 }             } } 

please note directly using application.current.resources, might have modify code bit..

if need save color , apply next time user opens application need save application settings (or settings file may maintaining) , on load of application apply color change code..!


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -