0
votes

I have a Main window with textbox. I enter some text and click enter it popups a window with listbox and displays the items matching the text entered in the Mainwindow. On selecting the item from the ListBox the text gets set in my textbox of Mainwindow.

I am following the MVVM Pattern. I am not able to set the binding for my listbox in my Mainwindow.(Using CommandBinding)

Does anyone has some solution or sample for the similar scenario?

Thanks

1

1 Answers

0
votes

On the ViewModel you need a property SelectedListBoxItem

Bind it to the SelectedItem of your ListBox.

Bind the Text-property to the SelectedListBoxItem of your ViewModel

and that should basically be it.

<ListBox
        ItemsSource="{Binding Path=ItemsView, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}"    
        SelectedItem="{Binding Path=SelectedListBoxItem, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}"
        />

<TextBox Text="{Binding Path=SelectedListBoxItem, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}"
        />