开发者

WPF Binding nightmares

开发者 https://www.devze.com 2023-02-12 21:33 出处:网络
So I have a Class public class ObjectDataModel { public ObservableCollection<ObjectClassA> MyObjectCollection;

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

精彩评论

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

关注公众号