c# - How to bind an `ObservableCollection` to Grid with Rows/Columns specified in the objects? -


i have inside grid:

    <ellipse grid.row="{binding path=game.tiles[2].row}"              grid.column="{binding path=game.tiles[2].column}"              fill="{binding game.tiles[2].fillcolor}"              stroke ="{staticresource tilestroke}"></ellipse> 

how enumerate on 24 objects without typing 24 times?

in order have list/collection of objects displayed, need employ "itemscontrol" of sorts. in case, following fragment might of help:

<itemscontrol itemssource="{binding game.tiles}">     <itemscontrol.itemspanel>         <itemspaneltemplate>             <grid>                 <grid.rowdefinitions>                     <rowdefinition height="*"/>                     <rowdefinition height="*"/>                      <rowdefinition height="*"/>                 </grid.rowdefinitions>                 <grid.columndefinitions>                     <columndefinition width="*"/>                     <columndefinition width="*"/>                     <columndefinition width="*"/>                 </grid.columndefinitions>             </grid>         </itemspaneltemplate>     </itemscontrol.itemspanel>     <itemscontrol.itemcontainerstyle>         <style>             <setter property="grid.column" value="{binding column}" />             <setter property="grid.row" value="{binding row}" />         </style>     </itemscontrol.itemcontainerstyle>     <itemscontrol.itemtemplate>         <datatemplate datatype="{x:type local:position}">             <ellipse fill="{binding fillcolor}"                      stroke="{staticresource tilestroke}"/>         </datatemplate>     </itemscontrol.itemtemplate> </itemscontrol> 

remember put in right datatype datatemplate , enough rows/columns grid hold data.

also not quite easy include unknown number of rows/columns. if of interest, getting solution, original post read idea of game board - checkers - assume number of columns/rows constant.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -