c# - Change slider bar color -


it should easy haven't fount information need. want simple changing color of slider bar:

enter image description here

i'm using modernui , default bar color similar background , want make bit lighter.

i found 2 approaches:

  1. you can customize slider insert corresponding brushes in appropriate slider.resources section.

  2. you can add brushes separate xaml file dictionary , merge corresponding slider in slider.resources. in cases fits better because can change colors of few controls @ once.

any not need changing of control's template.

both approaches presented below:

page1.xaml

<grid style="{staticresource contentroot}">      <stackpanel>          <!-- slider default theme , colors modernui -->         <slider/>          <!-- slider custom colors approach 1 -->         <slider>             <slider.resources>                 <solidcolorbrush x:key="sliderselectionbackground" color="green" />                 <solidcolorbrush x:key="sliderselectionborder" color="green" />                 <solidcolorbrush x:key="sliderthumbbackground" color="green" />                 <solidcolorbrush x:key="sliderthumbbackgrounddisabled" color="green" />                 <solidcolorbrush x:key="sliderthumbbackgrounddragging" color="green" />                 <solidcolorbrush x:key="sliderthumbbackgroundhover" color="green" />                 <solidcolorbrush x:key="sliderthumbborder" color="green" />                 <solidcolorbrush x:key="sliderthumbborderdisabled" color="green" />                 <solidcolorbrush x:key="sliderthumbborderdragging" color="green" />                 <solidcolorbrush x:key="sliderthumbborderhover" color="green" />             </slider.resources>         </slider>          <!-- slider custom colors approach 2 -->         <slider>             <slider.resources>                 <resourcedictionary>                     <resourcedictionary.mergeddictionaries>                         <resourcedictionary source="dictionary1.xaml"/>                     </resourcedictionary.mergeddictionaries>                 </resourcedictionary>             </slider.resources>         </slider>      </stackpanel>  </grid> 

dictionary1.xaml

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">  <solidcolorbrush x:key="sliderselectionbackground" color="blue" /> <solidcolorbrush x:key="sliderselectionborder" color="blue" /> <solidcolorbrush x:key="sliderthumbbackground" color="blue" /> <solidcolorbrush x:key="sliderthumbbackgrounddisabled" color="blue" /> <solidcolorbrush x:key="sliderthumbbackgrounddragging" color="blue" /> <solidcolorbrush x:key="sliderthumbbackgroundhover" color="blue" /> <solidcolorbrush x:key="sliderthumbborder" color="blue" /> <solidcolorbrush x:key="sliderthumbborderdisabled" color="blue" /> <solidcolorbrush x:key="sliderthumbborderdragging" color="blue" /> <solidcolorbrush x:key="sliderthumbborderhover" color="blue" />  </resourcedictionary> 

as result following:

result


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -