c# - Specify Left, Top Coordinates in ItemsControl with Shape Items -


i'm having issues binding itemscontrol collection contains shapes. don't need datatemplate, want specify top/left location of items contained in collection.

<itemscontrol x:name="regions" datacontext="{binding path=model}" itemssource="{binding path=items}">                     <itemscontrol.itemspanel>                         <itemspaneltemplate>                             <canvas x:name="canvas" background="yellow" />                         </itemspaneltemplate>                     </itemscontrol.itemspanel>                 </itemscontrol>  public model model {get;} public class model : inotifypropertychanged {     public observablecollection<element> items {get;} } public class element : shape {     public override system.windows.media.geometry geometry {get;} } 

i tried using itemscontrol.itemcontainerstyle, got binding error:

                      <itemscontrol.itemcontainerstyle>                         <style>                             <setter property="canvas.left" value="{binding geometry.bounds.left}" />                             <setter property="canvas.top" value="{binding geometry.bounds.top}" />                         </style>                     </itemscontrol.itemcontainerstyle>  system.windows.data error: 40 : bindingexpression path error: 'geometry' property not found on 'object' ''model' (hashcode=41545796)'. bindingexpression:path=geometry.bounds.top; dataitem='model' (hashcode=41545796); target element 'element' (name=''); target property 'top' (type 'double') 

it looks geometry property being applied model, rather element.

i added converter debug purposes:

<setter property="canvas.left" value="{binding ., converter={staticresource debugconverter}}" /> 

when set breakpoint in debugconverter, passed in "object" of type model rather element. seems wrong, expect element. how element?

there seems known issue datacontext being "reset" on itemcontainerstyle because evaluated before binding occurs. ended explicitly calling canvas.setleft() , canvas.settop() when construct model. not ideal solution, worked.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -