wpf - Dynamic Resources and Merged Dictionaries levels -


i have following configuration of resource dictionaries:

colorsdic.xaml contains

<color x:key="mycolor">#ff39adfb</color> <solidcolorbrush x:key="genericbackcolor" color="{dynamicresource  mycolor}"/> <solidcolorbrush x:key="controldark" color="{dynamicresource mycolor}"/> <solidcolorbrush x:key="controllight" color="{dynamicresource mycolor}" opacity="0.3"/> 

maindic.xaml contains

<resourcedictionary.mergeddictionaries >   <resourcedictionary source="./recursos/colorsdic.xaml"/> </resourcedictionary.mergeddictionaries >  <style x:key="mybuttonstyle" targettype="{x:type button}" >     <setter property="background" value="{staticresource genericbackcolor}"></setter>     <setter property="foreground" value="{binding path=background,relativesource={relativesource self}, converter={staticresource backtoforecolor}}"></setter> </style> 

now problem: i'd made user control includes button style defined before , main background color set "controldark" solid brush. when change value of "mycolor" application main window, button takes changes not background of user control. wrong?

thanks!!

try changing button style's background property setter dynamicresource staticresource.

if you're trying change colors @ run time static resource grabs resource when instantiated , doesn't update when resource changed.

edit: if issue user control's background can set background of user control using border:

<grid>     <!-- pick backgound color here-->     <border background="red"/>      <button content="test" height="20" width="50"/> </grid> 

or set background on user control transparent if user control not need background , controls inside of do:

<usercontrol x:class="usercontrol1"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"           mc:ignorable="d"           xmlns:local="clr-namespace:wpfapplication5"          background="transparent">     <grid>         <button content="test" height="20" width="50"/>     </grid> </usercontrol> 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -