开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜