HandyOrg / HandyOrg/HandyControl

hc:SideMenu侧边菜单通过代码修改选中项,无法触发鼠标的事件怎么办?

Open
#1,634 1 comment 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

Feature request type

enhancement

Is your feature request related to a problem? Please describe

我想通过点击一个按钮而不是菜单进行修改侧边菜单的选中状态,代码中sideMenuItem.IsSelected = true;修改后,无法触发sideMenuItem中受保护的OnSelected方法,导致我再次点击原先菜单项发现选中状态同时出现两个选中的。

Describe the solution you'd like

我想从某个页面中的按钮点击,然后修改菜单选中状态,如何实现呢?

Describe alternatives you've considered

No response

Additional context

///


/// 更新菜单选中状态
///

///
private void UpdateSideMenuSelected(SideMenuMessage message)
{
foreach (var item in SideMenu.Items)
{
if (item is SideMenuItem sideMenuItem)
{
if (sideMenuItem.Tag != null && message.MenuItemTag != null)
{
if (sideMenuItem.Tag.ToString() == message.MenuItemTag)
{
sideMenuItem.IsSelected = true;
}
}

        if (sideMenuItem.HasItems)
        {
            foreach (var subItem in sideMenuItem.Items)
            {
                if (subItem is SideMenuItem subSideMenuItem)
                {
                    if (subSideMenuItem.Tag != null && message.MenuItemTag != null)
                    {
                        if (subSideMenuItem.Tag.ToString() == message.MenuItemTag)
                        {
                            sideMenuItem.IsSelected = true;
                        }
                    }
                }
            }
        }
    }
}

}

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 by inspecting the SideMenu and SideMenuItem selection handling, including the protected OnSelected method, then reproduce the behavior with the provided UpdateSideMenuSelected method. Done means selecting an item from code produces the same selection behavior as a mouse click and does not leave multiple items selected.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.