WPF Binding nightmares
So I have a Class
public class ObjectDataModel
{
public ObservableCollection<ObjectClassA> MyObjectCollection;
}
public class ObjectClassA
{
public ObjecttypeA myobject;
public BitmapImage mybmp;
}
N开发者_运维百科ow I have a grid control whose ItemsSource
I wish to bind to myObject
of MyObjectCollection
.
How to do that?
You must expose ur binding target as Properties not as Fields (like you currently do).
<Window>
<Window.DataContext><local:ObjectDataModel/></Window.DataContext>
<Grid>
<ListView ItemsSource={Binding MyObjectCollection}/>
</Grid>
</Window>
Have you tried to achieve this, if yes then it will be great if you can post your XAML code.
As per my understanding this is the correct way of using this class -
<ItemsControl
Margin="5,0,5,5"
ItemsSource="{Binding Path=MyObjectCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid >
<TextBlock
Grid.Column="0"
Margin="0,5,0,0"
Width="Auto"
Text="{Binding Path=myobject.Property1}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
精彩评论