views:

29

answers:

1

Ok this might be simple or just not possible. Probably it's something that is frowned upon.

Let's say I have a combobox and a button beside it. I choose a item from the combobox and press the button.

In my button handler I guess I'm supposed to fetch combobox.selectedValue to get the item ( is there a better way).

Let's say I don't have access to the combobox where the eventhandler is could I bind the button somehow to the selectedvalue so I would have access to it through the button?

    private void addItemClick(object sender, RoutedEventArgs e)
    {
          collection.add( classFactory.NewInstanceOfId( (sender as button).DataContainer);
    }

Is this something you shouldn't do? Does Combobox perhaps have some inherit event to do this (I want a button to confirm). If I include the button inside the ComboBox somehow I guess I could use Button.DataContext ?

+2  A: 

You can bind the clicked to a command and have the command parameter set to the selected value.

Have a look here (although not exactly what you want but illustrates how to do it):

http://stackoverflow.com/questions/1350598/passing-two-command-parameters-using-a-wpf-binding

Aliostad
This is what I was searching for, thanks.
Ingó Vals