I am having a problem, I have a datatable data with 3 columns(ID,NAME,QUANTITY), I want to bind it with a ListBox, and make ListBox shows values from column NAME and QUANTITY,otherwise when I double click in a selected item,it will send ID value, here is my XAML:
<ListBox HorizontalAlignment="Left" Margin="6,0,0,0" Name="ListBox1" VerticalAlignment="Top" Height="600" Width="321">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseDoubleClick" Handler="ListBox1Item_DoubleClick" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Resources>
<DataTemplate x:Key="listBoxTemplate">
<DockPanel >
<TextBlock FontWeight="Bold" Text="{Binding NAME}"
DockPanel.Dock="Left"
Margin="5,0,10,0" Width="100"/>
<TextBlock Text="{Binding QUANTITY} " Foreground="Green" FontWeight="Bold" />
</DockPanel>
</DataTemplate>
</ListBox.Resources>
</ListBox>
Here is my code behind:
...
ListBox1.ItemsSource = data.DefaultView;
ListBox1.SelectedValuePath = "ID";
...
But it does not show anything, something wrongs? please help! thanks for reading this!