c# - In XAML how to copy a resource to a different tag name dynamically -


my question identical one:

how assign wpf resources other resource tags

except question works static resources. want know how dynamic resources. in detail:

i'm using resources 'class variables' control color of object. have this:

<style x:key="customscrollbarstyle" targettype="{x:key scrollbar}">     <style.resources>         <solidcolorbrush x:key="highlightcolor" color="blue"/>     </style.resources>     <setter property="template".../>  </style> 

and can customize color whenever use scrollbar:

<scrollbar>     <scrollbar.resources>         <solidcolorbrush x:key="highlightcolor" color="yellow">/     </scrollbar.resources> </scrollbar> 

this works well, provided reference highlightcolor {dynamicresource}. don't know how bring 1 level higher. example have combo box has it's own color style. want use color on scrollbars also:

<style x:key="comboboxstyle1" targettype="{x:type combobox}">     <style.resources>         <solidcolorbrush x:key="comboboxcolor" color="black"/>     </style.resources>     ...     <controltemplate>         <scrollbar>             <solidcolorbrush x:key="highlightcolor" ???? use comboboxcolor/>         </scrollbar>     </controltemplate>     ... </style> 

i've tried using binding, gives exception binding source can't dynamicresource. if bind color staticresource uses default color. i've tried creating dynamicresource directly complains works dependency property , can't inserted directly resource dictionary.

so how can dynamically create new resource existing one?

thanks.

update looks there's no way this. i've decided use attached properties instead. work perfectly.

why don't create color resource this

<color x:key="keyname">#112233</color> 

and set value brushes.

in code provided, trying set property of color type solidcolorbrush value.


Comments