Quantcast
Viewing all articles
Browse latest Browse all 256

How to bind a listbox and combobox?

Hi!

I want to show the exact same content in a listbox and a combobox. Is there an easy way to bind the items collection of the listbox to the items collection to the combobox?

Here is my code:
Code:

<Window x:Class="BetterTabView.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:b="BetterWpfControls"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel Orientation="Horizontal">
        <ListBox x:Name="myListBox" Width="180">
            <ListBoxItem>Donald</ListBoxItem>
            <ListBoxItem>Mickey</ListBoxItem>
            <ListBoxItem>Daisy</ListBoxItem>
            <ListBoxItem>Goofy</ListBoxItem>
        </ListBox>

        <ComboBox  Width="180" Height ="20" x:Name="cmbItems" ItemsSource="{Binding myListBox.Items, Mode=OneWay}" >
        </ComboBox>
    </StackPanel>

     
 
</Window>

kind regards
Henrik

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>