wpf - Set the ContentPresenter's content color, when the content is not a text -


let's contentpresenter contains viewbox paths inside instead of text, how change color of paths content presenter

example

i have resourcedictionary :

    <resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">             <viewbox>               <grid>                 <grid name="backgroundgrid" width="48" height="48" visibility="collapsed" />                 <path data="m19.833,0l32.5,0 32.5,19.833999 52.334,19.833999 52.334,32.500999 32.5,32.500999 32.5,52.333 19.833,52.333 19.833,32.500999 0,32.500999 0,19.833999 19.833,19.833999z"  stretch="uniform"  fill="?????"  width="26" height="26" margin="0,0,0,0" rendertransformorigin="0.5,0.5">                   <path.rendertransform>                     <transformgroup>                       <transformgroup.children>                         <rotatetransform angle="0" />                         <scaletransform scalex="1" scaley="1" />                       </transformgroup.children>                     </transformgroup>                   </path.rendertransform>                 </path>               </grid>             </viewbox>         </resourcedictionary> 

and have contentpresenter in controltemplate of let's button:

<controltemplate targettype="{x:type local:iconbutton}">        <border>           <grid>                                           <contentpresenter x:name="contentpresentericon" contentsource="icon"/>                                   </grid>        </border> ... 

assigning icon contentsource property means contentpresenter having viewbox content.

what should put in fill property of path element, , property should change in contentpresenter make value propagate fill property ?

hope clear.

update :

i desperately tried set contentpresenter's textelement.foreground property , "relativesource" bind path's fill property it, predictably didn't work.

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">                 <viewbox>                   <grid>                     <grid name="backgroundgrid" width="48" height="48" visibility="collapsed" />                     <path data="m19.833,0l32.5,0 32.5,19.833999 52.334,19.833999 52.334,32.500999 32.5,32.500999 32.5,52.333 19.833,52.333 19.833,32.500999 0,32.500999 0,19.833999 19.833,19.833999z"      stretch="uniform"      fill="{binding path=textelement.foreground, relativesource={relativesource ancestortype={x:type contentpresenter}}}"      width="26" height="26" margin="0,0,0,0" rendertransformorigin="0.5,0.5">                       <path.rendertransform>                         <transformgroup>                           <transformgroup.children>                             <rotatetransform angle="0" />                             <scaletransform scalex="1" scaley="1" />                           </transformgroup.children>                         </transformgroup>                       </path.rendertransform>                     </path>                   </grid>                 </viewbox> 

<controltemplate targettype="{x:type local:iconbutton}">            <border>               <grid>                                               <contentpresenter x:name="contentpresentericon" textelement.foreground="red" contentsource="icon"/>                                       </grid>            </border>     ... 

your second attempt should have worked. reason didn't because binding attached property.

attached property binding requires special syntax. output window in visual studio tells path not found. should work:

fill="{binding path=(textelement.foreground), relativesource={relativesource ancestortype={x:type contentpresenter}}}"  

the change parenthesis around path string. more information, see wpf attached property data binding.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -