mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
source code checkin
This commit is contained in:
parent
5f8fb2c825
commit
7e57b72e35
675 changed files with 168433 additions and 0 deletions
53
src/ServerManager.Common/Controls/DropDownButton.cs
Normal file
53
src/ServerManager.Common/Controls/DropDownButton.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ServerManagerTool.Common.Controls
|
||||
{
|
||||
public class DropDownButton : ToggleButton
|
||||
{
|
||||
public DropDownButton()
|
||||
{
|
||||
// Bind the ToogleButton.IsChecked property to the drop-down's IsOpen property
|
||||
Binding binding = new Binding("Menu.IsOpen")
|
||||
{
|
||||
Source = this
|
||||
};
|
||||
this.SetBinding(IsCheckedProperty, binding);
|
||||
|
||||
DataContextChanged += (sender, args) =>
|
||||
{
|
||||
if (Menu != null)
|
||||
{
|
||||
Menu.DataContext = DataContext;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MenuProperty = DependencyProperty.Register("Menu", typeof(ContextMenu), typeof(DropDownButton), new UIPropertyMetadata(null, OnMenuChanged));
|
||||
public ContextMenu Menu
|
||||
{
|
||||
get { return (ContextMenu)GetValue(MenuProperty); }
|
||||
set { SetValue(MenuProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnMenuChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var dropDownButton = (DropDownButton)d;
|
||||
var contextMenu = (ContextMenu)e.NewValue;
|
||||
contextMenu.DataContext = dropDownButton.DataContext;
|
||||
}
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
if (Menu != null)
|
||||
{
|
||||
// If there is a drop-down assigned to this button, then position and display it
|
||||
Menu.PlacementTarget = this;
|
||||
Menu.Placement = PlacementMode.Bottom;
|
||||
Menu.IsOpen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue