N
N
NameOf Var2017-06-03 17:08:49
WPF
NameOf Var, 2017-06-03 17:08:49

What is the correct way to bind an array in WPF?

The point is this. There are two classes: Cart and Item:

public class Cart
{
      public Item[] Items { get; set; }
      public double Price { get; set; }
}

public class Item
{
      public int Id { get; set; }
      public string Description { get; set; }

It is necessary to display all Item's in ListBox'e according to the template: ID: Description.
How to properly describe the ListBox template?
<ListBox ItemsSource="{StaticResource cart}" Width="350" Margin="0,5,0,10">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Id}" />
                        <TextBlock Text=", " />
                        <TextBlock Text="{Binding Descritpion}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TolegBoleg, 2017-06-04
@TolegBoleg

ItemsSource="{StaticResource cart.Items}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question