HandyOrg / HandyOrg/HandyControl

[Feature request] SplitButton toggle DropDown open

Open
#1,417 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
7.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

HandiControl 提供了 ContextMenuToggleButton,它能通过鼠标左键切换打开菜单,SplitButton 也支持打开下拉项(“菜单”),但是它的行为类似于平时的右键菜单行为,不论 DropDown 是否打开,右键都将重新打开 DropDown,我希望当 DropDown 打开时,再次点击鼠标左键,将收起 DropDown

现在的临时解决方法是这样:

HandiControl provides ContextMenuToggleButton, which can open the menu by left mouse button toggle, SplitButton also supports opening dropdown items ("menu"), but its behavior is similar to the usual right-click menu behavior, no matter DropDown is open or not, right-clicking will re-open DropDown, and I want that when DropDown is open, clicking the left mouse button again will put away DropDown.
The temporary workaround now is this:

public class SplitButtonToggleDropDownBehavior : Behavior<SplitButton>
{
    protected override void OnAttached()
    {
        base.OnAttached();

        AssociatedObject.PreviewMouseLeftButtonDown += AssociatedObject_PreviewMouseLeftButtonDown;
    }

    protected override void OnDetaching()
    {
        AssociatedObject.PreviewMouseLeftButtonDown -= AssociatedObject_PreviewMouseLeftButtonDown;

        base.OnDetaching();
    }

    private void AssociatedObject_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        var result = VisualTreeHelper.HitTest(AssociatedObject, e.GetPosition(AssociatedObject));

        // 如果 VisualHit 为 Border 或 Path,则鼠标在点击 SplitButton 的 DropDown 位置,
// If VisualHit is Border or Path, the mouse is clicking on the DropDown position of the SplitButton.
        // 如果为 TextBlock,则鼠标在点击 SplitButton 的非 DropDown 位置。
// If TextBlock, the mouse is clicking on the non-DropDown position of the SplitButton.
        // 如果为 null,则鼠标在点击其他位置。
// If it is null, then the mouse is clicking on other position.
        // 如果不判断 VisualHit,则在点击下拉项前,此事件将被调用,下拉项被关闭,导致下拉项无法被点击到。
// If VisualHit is not judged, this event will be called before the dropdown item is clicked and the dropdown item is closed, causing the dropdown item not to be clicked to.

        if (AssociatedObject.IsDropDownOpen && result?.VisualHit is Border or Path or TextBlock)
        {
            AssociatedObject.IsDropDownOpen = false;
            e.Handled = true;
        }
    }
}

所以能否提供一个属性 IsToggleDropDownOpen?

So could you provide a property IsToggleDropDownOpen?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SplitButton control and its DropDown open-state handling; no specific source file or test is named in the issue. Compare the requested toggle behavior with the supplied SplitButtonToggleDropDownBehavior workaround, then verify that the new property closes an open DropDown on the requested click without preventing dropdown-item clicks.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.