wpf - Path from Resources as Content of Button -


i set button's content path defined in resources. created usercontrol, defined path, 2 brushes , button style in resources... , ok.

<usercontrol ...>     <usercontrol.resources>         <path x:key="pagesmallicon2" stretch="fill" fill="{binding relativesource={relativesource findancestor, ancestortype={x:type control}}, path=foreground}" stroke="{binding relativesource={relativesource findancestor, ancestortype={x:type control}}, path=foreground}" snapstodevicepixels="true" data="f1 m 19,25l 27,25l 27,33l 19,33l 19,25 z m 19,36l 27,36l 27,44l 19,44l 19,36 z m 31,25l 57,25l 57,33l 31,33l 31,25 z m 19,47l 27,47l 27,55l 19,55l 19,47 z "/>         <solidcolorbrush x:key="maincolorbrush2" color="orange"/>         <solidcolorbrush x:key="whitecolorbrush2" color="whitesmoke"/>         <style x:key="transparentbuttonstyle2" targettype="{x:type button}">             <setter property="foreground" value="{staticresource whitecolorbrush2}"/>             <setter property="height" value="25"/>             <setter property="width" value="25"/>             <setter property="template">                 <setter.value>                     <controltemplate targettype="{x:type button}">                         <grid>                             <rectangle fill="transparent"/>                             <contentpresenter x:name="contentpresenter" content="{templatebinding content}" margin="2" />                         </grid>                         <controltemplate.triggers>                             <trigger property="ispressed" value="true">                                 <setter property="foreground" value="{staticresource maincolorbrush2}"/>                             </trigger>                         </controltemplate.triggers>                     </controltemplate>                 </setter.value>             </setter>         </style>     </usercontrol.resources>     <grid>         <button command="{binding path=smallpagesizecommand}" style="{staticresource transparentbuttonstyle2}" content="{staticresource pagesmallicon2}"/>         ...     </grid> </usercontrol> 

i decided put resources in separate resourcedictionaries. plan have more paths , brushes... have 1 style button. doing this, because had style each of buttons , path each specific button part of button's controltemplate.

so created 3 resourcedictionaries colors.xaml, icons.xaml , controls.xaml , updated app.xaml

<application.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="theme/colors.xaml"/>             <resourcedictionary source="theme/icons.xaml"/>             <resourcedictionary source="theme/controls.xaml"/>         </resourcedictionary.mergeddictionaries>     </resourcedictionary> </application.resources> 

now path's fill property not updated when press button. please explain why not work in separate resourcedictionaries , provide me solution problem?

update

so discovered problem in path. when have path in <usercontrol.resources>, colors in colors.xaml , button style in controls.xaml works again.

i discovered when have path in icons.xaml , use in usercontrol button's content

<button command="{binding path=smallpagesizecommand}" style="{staticresource transparentbuttonstyle2}" content="{staticresource pagesmallicon2}"/> 

and have multiple instances of usercontrol... path present in 1 instance of usercontrol @ time.

the reason for:

i have multiple instances of usercontrol... path present in 1 instance of usercontrol @ time

is because giving same element different parents in xaml. setting content of multiple button controls path shape defined in resources. optimization purposes each reference resource return default same instance of object , since in wpf each element can have 1 parent @ time, last button in xaml declaration have it's content set desired path. solve can mark resource x:shared="false" attribute. in case xaml parser generate new instance of path element each reference.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -