// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Defines the DropDownButton type. // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Controls.DropButton { using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; /// /// The drop down button. /// public class DropButton : ToggleButton { /// /// The drop down property. /// public static readonly DependencyProperty DropDownProperty = DependencyProperty.Register("DropDown", typeof(ContextMenu), typeof(DropButton), new UIPropertyMetadata(null)); /// /// Initializes a new instance of the class. /// public DropButton() { // Bind the ToogleButton.IsChecked property to the drop-down's IsOpen property Binding binding = new Binding("DropDown.IsOpen") { Source = this }; this.SetBinding(IsCheckedProperty, binding); } /// /// Gets or sets the drop down. /// public ContextMenu DropDown { get { return (ContextMenu)this.GetValue(DropDownProperty); } set { this.SetValue(DropDownProperty, value); } } /// /// Handle the users click on the button. /// protected override void OnClick() { if (this.DropDown != null) { // If there is a drop-down assigned to this button, then position and display it this.DropDown.PlacementTarget = this; this.DropDown.Placement = PlacementMode.Bottom; this.DropDown.IsOpen = true; } } } }