Ive created a custom UserControl that contains a single combobox. The currently selected value in the combobox is bound to the custom UserControls Dependency Property.
XAML:
<UserControl>
<ComboBox
ItemsSource="{Binding AllEntries}"
SelectedItem="{Binding SelectedEntry}" />
</UserControl>
Code behind:
public partial class MyCombobox : UserControl
{
public static DependencyProperty SelectedEntryProperty =
DependencyProperty.Register("SelectedEntry",
typeof(ComboboxEntry),
typeof(MyCombobox));
public ComboboxEntry SelectedEntry
{
get { return (ComboboxEntry)GetValue(SelectedEntryProperty); }
set { SetValue(SelectedEntryProperty, value); }
}
}
Now the problem is that another component includes this extended combobox control. In the containing control I want to run some logic when the user selects a new value in the combobox. Im a bit lost as to how I set up that hook. Must MyCombobox
expose a custom event which is fired from a PropertyChanged callback in the SelectedEntry Dependency Property? Seems hacky but I cant figure out another way.