wpf - ListBox binding DataTemplate item to ItemsPanel Canvas.Left/Top -


i have listbox canvas itemspanel. items in list labeledarrows:labeled arrow example

labeledarrow view model class (non visual) exposes properties start_x, start_y (arrow start), end_x, end_y (arrow head) , box_x, box_y (box possition) listboxitem datatemplate labeledarrow shown below.
binding of arrowline x1, y1, x2, y2 labeledarrow start_x, start_y etc properties works fine because arrowline has exposed coordinate properties (x1 etc). box textblock have somehow set canvas.top , canvas.left attatched properties possition - binding shown below doesn't work.
ideas? do need resort wrapping labeledarrow usercontrol?

<listbox.resources>          <datatemplate datatype="{x:type tp:labledarrow}">     <grid>     <tp:arrowline stroke="red" strokethickness="2"           x1="{binding path=start_x}" y1="{binding path=start_y}"           x2="{binding path=end_x}" y2="{binding path=end_y}" />     <textblock text="{binding path=value}"                **canvas.left="{binding path=box_x}"                canvas.top="{binding path=box_y}"** />     </grid> </datatemplate> </listbox.resources>  <listbox.itemspanel>     <itemspaneltemplate>         <canvas isitemshost="true"  />     </itemspaneltemplate> </listbox.itemspanel> 

you set attached properties canvas.left , canvas.top on textbox, parent of textbox grid. attached properties used tell parent of control how layout element. canvas, grid , dockpanel example. want set both properties on item container, direct child of canvas. container uses datatemplate display content.

to add listbox

<listbox.itemcontainerstyle>     <style>         <setter property="canvas.left" value="{binding path=box_x}"/>         <setter property="canvas.top" value="{binding path=box_y}"/>     </style> </listbox.itemcontainerstyle> 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -