WPF Can a button carry data to it's event handler
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(ob开发者_C百科ject 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 ?
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):
Passing two command parameters using a WPF binding
精彩评论