内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list($forumlist, $model = 0, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $model . '-' . $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 不分模型 * @param int $display 0全部CMS栏目 1在首页和频道显示内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list_show($forumlist, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 * @return mixed BBS栏目数据(仅列表) 尚未开放bbs频道功能 */ function forum_list($forumlist) { if (empty($forumlist)) return array(); static $cache = array(); if (isset($cache['bbs_forum_list'])) return $cache['bbs_forum_list']; $cache['bbs_forum_list'] = array(); foreach ($forumlist as $_fid => $_forum) { if ($_forum['type']) continue; $cache['bbs_forum_list'][$_fid] = $_forum; } return $cache['bbs_forum_list']; } // 导航显示的版块 function nav_list($forumlist) { if (empty($forumlist)) return NULL; static $cache = array(); if (isset($cache['nav_list'])) return $cache['nav_list']; foreach ($forumlist as $fid => $forum) { if (0 == $forum['nav_display']) { unset($forumlist[$fid]); } } return $cache['nav_list'] = $forumlist; } ?>.net - Context Menu won't close after BlazoredPopup is open from the context menu - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - Context Menu won't close after BlazoredPopup is open from the context menu - Stack Overflow

programmeradmin0浏览0评论

I have this code that shows a BlazoredModal. The context Menu shows above the Modal instead of disappearing. It does disappear for the "Delete" and "ViewDetails" options.

    // Example context menu
private Task OnContextMenuOpen(ContextMenuOpenEventArgs<ExpandoObject> args) => Task.CompletedTask;

                    private async Task OnContextMenuItemClicked(ContextMenuClickEventArgs<ExpandoObject> args)
                {
                    if (args.RowInfo?.RowData is ExpandoObject rowData && args.Item.Text == "Edit")
                    {
                        Console.WriteLine("Edit action triggered.");
                        // Introduce a slight delay to allow the grid's context menu to close
                        // await Task.Delay(1000);
                        // Open the modal with the selected row data
                        var parameters = new ModalParameters();
                        parameters.Add("SelectedItem", rowData);
                        var result = await ModalService.Show<EditRowModal>("Edit Row", parameters).Result;
                    }
                    else if (args.Item.Text == "Delete")
                    {
                        Console.WriteLine("Delete action triggered.");
                        // Implement delete logic here

                    }
                    else if (args.Item.Text == "View Details")
                    {
                        Console.WriteLine("View Details action triggered.");
                        // Implement view details logic here

                    }
                
    private List<ContextMenuItemModel> _contextMenuItems = new()
    {
    new ContextMenuItemModel { Text = "Edit", IconCss = "e-icons e-edit", Id = "edit" },
    new ContextMenuItemModel { Text = "Delete", IconCss = "e-icons e-delete", Id = "delete" },
    new ContextMenuItemModel { Text = "View Details", IconCss = "e-icons e-eye", Id = "viewDetails" }
    };


            <SfGrid @ref="_gridRef" DataSource="@Items"
        AllowPaging="true"
        AllowSorting="true"
        AllowFiltering="true"
        AllowReordering="true"
        AllowResizing="true"
        GridLines="GridLine.Horizontal"
        ContextMenuItems="@_contextMenuItems"
        EnableStickyHeader="true">

The Modal/popup in fact opens after Edit is clicked (which is desired); but the context menu is supposed to be closed after that.

I have this code that shows a BlazoredModal. The context Menu shows above the Modal instead of disappearing. It does disappear for the "Delete" and "ViewDetails" options.

    // Example context menu
private Task OnContextMenuOpen(ContextMenuOpenEventArgs<ExpandoObject> args) => Task.CompletedTask;

                    private async Task OnContextMenuItemClicked(ContextMenuClickEventArgs<ExpandoObject> args)
                {
                    if (args.RowInfo?.RowData is ExpandoObject rowData && args.Item.Text == "Edit")
                    {
                        Console.WriteLine("Edit action triggered.");
                        // Introduce a slight delay to allow the grid's context menu to close
                        // await Task.Delay(1000);
                        // Open the modal with the selected row data
                        var parameters = new ModalParameters();
                        parameters.Add("SelectedItem", rowData);
                        var result = await ModalService.Show<EditRowModal>("Edit Row", parameters).Result;
                    }
                    else if (args.Item.Text == "Delete")
                    {
                        Console.WriteLine("Delete action triggered.");
                        // Implement delete logic here

                    }
                    else if (args.Item.Text == "View Details")
                    {
                        Console.WriteLine("View Details action triggered.");
                        // Implement view details logic here

                    }
                
    private List<ContextMenuItemModel> _contextMenuItems = new()
    {
    new ContextMenuItemModel { Text = "Edit", IconCss = "e-icons e-edit", Id = "edit" },
    new ContextMenuItemModel { Text = "Delete", IconCss = "e-icons e-delete", Id = "delete" },
    new ContextMenuItemModel { Text = "View Details", IconCss = "e-icons e-eye", Id = "viewDetails" }
    };


            <SfGrid @ref="_gridRef" DataSource="@Items"
        AllowPaging="true"
        AllowSorting="true"
        AllowFiltering="true"
        AllowReordering="true"
        AllowResizing="true"
        GridLines="GridLine.Horizontal"
        ContextMenuItems="@_contextMenuItems"
        EnableStickyHeader="true">

The Modal/popup in fact opens after Edit is clicked (which is desired); but the context menu is supposed to be closed after that.

Share Improve this question edited Feb 24 at 13:01 who-aditya-nawandar asked Feb 2 at 5:19 who-aditya-nawandarwho-aditya-nawandar 1,24211 gold badges50 silver badges105 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You could use async void instead of async Task which doesn't return "Task" for the method result.

private async void OnContextMenuItemClicked (..)

Or if you need the "Task", you could try close the context manually:

<SfContextMenu @ref="contextMenuRef" TValue="MenuItem" ...>
@code {
    SfContextMenu<MenuItem> contextMenuRef;
    private async Task OnContextMenuItemClicked(ContextMenuClickEventArgs<ExpandoObject> args){
        ...
        contextMenuRef.Close();
        var result = await ModalService.Show<EditRowModal>("Edit Row", parameters).Result;
    }
发布评论

评论列表(0)

  1. 暂无评论