Rkurel
Rkurel

Reputation: 85

C# WPF binding data in ListBox

i have a problem in WPF application with binding data in ListBox.

Here is me xaml code:

<Window x:Class="DatabaseBoozeWpf.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:DatabaseBoozeWpf"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="625">
<Grid>
    <ListBox
             Margin="10,124,0,10"
             ItemsSource="{Binding Boozes}" 
             HorizontalAlignment="Left"
             ScrollViewer.VerticalScrollBarVisibility="Visible"
             ItemTemplate="{Binding Boozes}"

             Width="233">

    </ListBox>

</Grid>

But if I open the program, it will show this kind on text. It should output the list of products. enter image description here

Upvotes: 0

Views: 87

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222722

You should have an ItemTemplate with a DataTemplate with elements that bind to the properties of the item class.

<ListBox ItemsSource="{Binding Boozes}" ...>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding YourProperty}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Upvotes: 2

Related Questions