c# - Overriding Button in XAML WPF with ControlTemplate does not display content -


i xaml newbie , looking @ blog

http://jeremybytes.blogspot.com/2009/03/wpf-xaml-sample.html

he mentions "notice not have content (button1a, button1b, etc.). because our template not contain element content." looking figure out how ensure content remains after new button template applied. here xaml

<page.resources>     <controltemplate targettype="button" x:key="targetbutton">         <canvas width="100" height="100" name="maincanvas">             <rectangle height="100" width="100" fill="aqua" canvas.top="1"/>              </canvas>     </controltemplate>             <style targettype="button">         <setter property="margin" value="5, 5, 5, 5"/>                     <setter property="template" value="{staticresource targetbutton}"/>     </style> </page.resources>  <stackpanel datacontext="{binding board}">     <stackpanel orientation="horizontal">         <button name="testbutton1a" click="testbutton1a_click" content="testbutton1a"/>         <button name="testbutton1b" click="testbutton1a_click" content="testbutton1b"/>         <button name="testbutton1c" click="testbutton1a_click" content="testbutton1c"/>     </stackpanel>     <stackpanel orientation="horizontal">         <button x:name="testbutton2a" click="testbutton1a_click" content="testbutton2a"/>         <button x:name="testbutton2b" click="testbutton1a_click" content="testbutton2b"/>         <button x:name="testbutton2c" click="testbutton1a_click" content="testbutton2c"/>     </stackpanel>     <stackpanel orientation="horizontal">         <button name="testbutton3a" click="testbutton1a_click" content="testbutton3a"/>         <button name="testbutton3b" click="testbutton1a_click" content="testbutton3b"/>         <button name="testbutton3c" click="testbutton1a_click" content="testbutton3c"/>     </stackpanel> </stackpanel> 

i have tried add textblock in template see same textblock overlayed across buttons. want render testbutton* content displayed on rectangle button matrix can change content once clicked.

thanks, appreciated

you can use contentpresenter display content:

<controltemplate targettype="button" x:key="targetbutton">    <canvas width="100" height="100" name="maincanvas">       <rectangle height="100" width="100" fill="aqua" canvas.top="1"/>       <contentpresenter/>    </canvas> </controltemplate> 

Comments