Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to access each ListView item's object, and get property from there?

I'm a beginner in WPF, and I havent't really found an answer (or I'm just really blind) on this issue. In the ListView I've binded an AllPosts List from my ViewModel, which contains "Post" typed objects, it has some properties like Body, Created_At etc, and an "User" object, which contains an UserName property, and I'd like to bind that to the GroupBox's header, and it doesn't really seem to work. Any thoughts on this?

<ListView Margin="10" ItemsSource="{Binding AllPosts}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <GroupBox Header="{Binding User.UserName}" Width="455">
                    <StackPanel>
                        <TextBlock Text="{Binding Body}"/>
                        <TextBlock Text="{Binding Created_At}"/>
                    </StackPanel>
                </GroupBox>
            </DataTemplate>
        </ListView.ItemTemplate>

Comments