Adding a ListBox control in the UI is as easy as writing a <ListBox /> tag in any XAML page. But to hold the data in it, you will have to use its properties properly. Follow these steps to add a ListBox control with some static data:
- Open the MainWindow.xaml page of the WPF project.
- Under the default Grid panel, add the <ListBox></ListBox> tag to add the control.
- Add a few ListBoxItem inside the control, as shared here:
<ListBox x:Name="lstBox" Width="120" Height="85" Margin="10 10 20 5"> <ListBoxItem Content="Item 1" /> <ListBoxItem Content="Item 2" IsSelected="True" /> <ListBoxItem Content="Item 3" /> <ListBoxItem Content="Item 4" /> <ListBoxItem Content="Item 5" /> </ListBox>
- Add two buttons labelled + and - to perform the add and delete operations on the said...