c# - How can my ItemsControl get the width property (from Items) -


i have small problem how set itemscontrol property width. use datatemplates fill itemcontrol. every item small grid (text , rectangle) in canvas.

when use itemscontrol in window actualwidth (and desiredwidth) 0.0.

only when hardcode width property of canvas itemscontrol has size. far perfect. rather when control gets width (or desiredwidth) biggest item.

here short code sample:

<itemscontrol itemssource="{binding mysource}"          itemtemplate="{dynamicresource mytemplate}">  <itemscontrol.resources>     <datatemplate datatype="{x:type type:mytype}"  x:key="mytemplate">         <grid width="auto" height="auto">             <grid.rowdefinitions>                 <rowdefinition height="auto"/>                 <rowdefinition/>             </grid.rowdefinitions>              <grid.columndefinitions>                 <columndefinition width="auto"/>                 <columndefinition/>             </grid.columndefinitions>              <rectangle grid.column="0"                        grid.columnspan="2"                        grid.row="1"                        height="1"                        horizontalalignment="stretch"                        fill="blue"/>              <textblock grid.row="0"                        grid.column="1"                        margin="3"                        text="{binding text}"                        fontweight="bold"                        textwrapping="wrap"                        textalignment="left"/>          </grid>     </datatemplate>     <v:positionmulticonverter x:key="positionmulticonverter"/> </itemscontrol.resources>  <itemscontrol.itemcontainerstyle>     <style>         <setter property="canvas.bottom">             <setter.value>                 <multibinding converter="{staticresource resourcekey=positionmulticonverter}">                     <binding path="position"/>                     <binding path="actualheight" elementname="canvas"/>                 </multibinding>             </setter.value>         </setter>     </style> </itemscontrol.itemcontainerstyle>  <itemscontrol.itemspanel>     <itemspaneltemplate>         <canvas x:name="canvas" isitemshost="true" width="20"/>     </itemspaneltemplate> </itemscontrol.itemspanel> 


Comments

Popular posts from this blog

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

android - Keyboard hides my half of edit-text and button below it even in scroll view -

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