WPF Get selected item from ListBox in VB.NET

In this article you will see how to get selected item from ListBox in WPF Application.
  • 3745

The ListBox control displays a list of items. The user can select one or multiple items depending on the selection mode. Here we will create an application in which, I have a ListBox with a list of colors, a TextBox, and a Ellipse.

When we pick a color from the ListBox, the text of TextBox and color of Ellipse changes dynamically to the color selected in the ListBox. Lets see the following XAML code snippet:

Xaml Code

Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="Compile XAML Window"
    <StackPanel Orientation="Vertical">
        <TextBlock Margin="10,10,10,10" FontWeight="Bold">
          Pick a color from below list 
        <ListBox Name="mcListBox" Height="100" Width="100"
             Margin="10,10,0,0" HorizontalAlignment="Center">
        <TextBox Height="23" Name="textBox1" Width="120" Margin="10,10,0,0" HorizontalAlignment="Center" >
                <Binding ElementName="mcListBox" Path="SelectedItem.Content"/>
        <Ellipse Stroke="Black" StrokeThickness="1"
                 Height="115" Width="148" ToolTip="An author.">
                <Binding ElementName="mcListBox" Path="SelectedItem.Content"/>

The output of the above code looks like:



In this article, I discussed how to select item from ListBox. I hope you will enjoy this article.


More Articles

© 2020 DotNetHeaven. All rights reserved.