.net - Define a color as a system color within a theme in WPF -
i want define solidcolorbrush
resource in wpf application (or rather in assembly several applications may refer to).
in themes want color explicitly defined in resource dictionary making theme, in example classic theme want color system color.
for example:
aero.normalcolor.xaml:
<solidcolorbrush x:key="{componentresourcekey typeintargetassembly={x:type l:myclass}, resourceid=mycolor}" color="#ff3399ff"/>
classic.xaml:
<solidcolorbrush x:key="{componentresourcekey typeintargetassembly={x:type l:myclass}, resourceid=mycolor}" color="{dynamicresource {x:static systemcolors.highlightcolorkey}}"/>
this brush should available application name mycolor
can re-defined on theme level. if defined above works should when color defined literal (i.e. when using aero theme), when referring systemcolors
dynamic resource (in classic.xaml) exception saying "this freezable can not frozen" during application startup. (at least if have several of these brushes defined, seems work in scenarios, such when using single color, doesn't seem stable anyway.
edit: usage like:
<border background="{dynamicresource {componentresourcekey typeintargetassembly={x:type l:myclass}, resourceid=mycolor}}">
it not seem easy reproduce. when created theme file 2 of these colors, , empty window line above in grid
program runs, designer within visual studio instead throws exception above. not quite sure how create minimal example reproduces in runtime.
so how can prevent error occurring, or method should using achieve goal here?
do realy need dynamic link system color? did try set static resource? mean change
color="{dynamicresource {x:static systemcolors.highlightcolorkey}}
to
color="{staticresource {x:static systemcolors.highlightcolorkey}}
does make sense?
seems design: http://www.vistax64.com/avalon/263-freezable-can-not-frozen-dynamicresource-x-static-systemcolors-controldarkdarkcolorkey.html
Comments
Post a Comment