wpf controls - Accessing Canvas properties inside DataTemplate, WPF -


i have datatemplate text , use itemcontrol place text inside canvas. how access canvas properties inside data template? in case if difficult want access individual textbox properties inside itemcontrol. reason need textcontrol alignment. both of datatemplate , itemcontrol code below

<datatemplate     datatype="{x:type local:text}">     <textblock text="{binding description}"                fontsize= "{binding thickness}"                 rendertransformorigin="0.5,0.5"                 foreground="#fff63aff"                 fontweight="bold" >       <textblock.rendertransform>         <transformgroup>             <translatetransform x= "{binding startpoint.x}" y= "{binding startpoint.y}"  />                                <rotatetransform angle= "{binding angle}"  />         </transformgroup>        </textblock.rendertransform>       </textblock> </datatemplate>     <itemscontrol itemssource="{binding path = textlist}">     <itemscontrol.itemspanel>         <itemspaneltemplate>              <canvas horizontalalignment="center" verticalalignment="center"                 width="0" height="0">                   <canvas.rendertransform>                 <transformgroup>                                          <scaletransform scalex="1" scaley="1"/>                                                 </transformgroup>                 </canvas.rendertransform>             </canvas>         </itemspaneltemplate>     </itemscontrol.itemspanel> </itemscontrol>  

if want customize layout of itemscontrol's children , available panels don't deliver need, have build own panel. here introduction topic: http://www.codeproject.com/articles/15705/fisheyepanel-fanpanel-examples-of-custom-layout-pa

the difficulty depends on layout like. inside panel can access elements properties layout logic. example if wanted align multiline textboxes on right side of panel , single line textboxes left, easy do. :)

if elaborate little more want achieve can give better guidance.

---- edit --- canvas.left , others attachedproperties. can example bind against assigned values inside template using following syntax:

myproperty="{binding path=(canvas.left), relativesource={relativesource templatedparent}}" 

---- edit 2 ---

so here's sample should want. in viewmodel there's collection containing points (x & y). these rendered inside itemscontrol canvas panel. tricky part around each element there's contentpresenter, binding canvas values button in itemtemplate not work. therefore added itemcontainerstyle:

mainwindow.xaml

<window x:class="wpfapplication7.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="mainwindow" height="350" width="525" >     <itemscontrol itemssource="{binding locations}">         <itemscontrol.itemspanel>             <itemspaneltemplate>                 <canvas />             </itemspaneltemplate>         </itemscontrol.itemspanel>         <itemscontrol.itemtemplate>             <datatemplate datatype="point">                 <button content="{binding}" width="40" height="20" />             </datatemplate>         </itemscontrol.itemtemplate>         <itemscontrol.itemcontainerstyle>             <style targettype="contentpresenter">                 <setter property="canvas.left"                     value="{binding x}" />                 <setter property="canvas.top"                     value="{binding y}" />             </style>         </itemscontrol.itemcontainerstyle>     </itemscontrol> </window> 

mainwindow.xaml.cs:

public partial class mainwindow : window     {         public mainwindow()         {             initializecomponent();             this.datacontext = new viewmodel();         }     } 

viewmodel:

public class viewmodel : inotifypropertychanged     {         public viewmodel()         {             locations = new observablecollection<point>             {                 new point(10,10),                 new point(20,20),                 new point(30,30),                 new point(50,60),             };         }          public observablecollection<point> locations { get; set; }          #region inotifypropertychanged support          public event propertychangedeventhandler propertychanged;          [notifypropertychangedinvocator]         protected virtual void onpropertychanged([callermembername] string propertyname = null)         {             propertychangedeventhandler handler = propertychanged;             if (handler != null) handler(this, new propertychangedeventargs(propertyname));         }          #endregion      } 

try that, believe should looking for. :)


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -