Groups | Blog | Home
all groups > dotnet windows forms databinding > march 2008 >

dotnet windows forms databinding : data binding a collection onto a canvas


Steve Mills
3/22/2008 9:36:41 PM
I have an ObservableCollection of objects that encode a reference to
an image with left, top, width, and height. I want to data bind them
onto a Canvas in a WPF Window. What I've tried uses:

<DataTemplate x:Key="ImageTemplate">
<Image
Source="{Binding Path=Key, Converter={StaticResource
magePathConverter}}"
Width="{Binding Path=Width}"
Height="{Binding Path=Height}"

<Canvas.Left><Binding Path=Left" /> </Canvas.Left>
<Canvas.Top><Binding Path=Top" /> </Canvas.Top>

</Image>
</DataTemplate>


<ListBox Name="Images"
ItemTemplate="{StaticResource ImageTemplate}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>


The images show up on the Canvas just fine, EXCEPT that the left and
top all come out == 0.0. The image file is picked up, the width and
height are fine, but not left and top.


All suggestions welcome.


AddThis Social Bookmark Button