protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { base.OnPropertyChanged(e); if (e.Property == ValueProperty) { var type = e.NewValue.GetType(); if (currentEnumType != type) { currentEnumType = type; uxPanel.Children.Clear(); foreach (var v in Enum.GetValues(type)) { var b = new EnumButton(); b.Value = v; b.Content = Enum.GetName(type, v); b.SetBinding(StyleProperty, new Binding("ButtonStyle") { Source = this }); b.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(button_PreviewMouseLeftButtonDown); uxPanel.Children.Add(b); } } UpdateButtons(); UpdateContainer(); } else if (e.Property == ContainerProperty) { UpdateContainer(); } }