This is a migrated thread and some comments may be shown as answers.

ContextMenu Add items where expand

1 Answer 41 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Andrey asked on 11 Oct 2012, 04:06 PM
in XAML: 

<telerik:RadContextMenu.ContextMenu>
    <telerik:RadContextMenu>
    <telerik:RadMenuItem Header="Sub Item 1"/>
                <telerik:RadMenuItem Header="Sub Item 2" Style="{StaticResource RadContextMenuItemStyle}" ItemsSource="{Binding Groups}"
                                       MouseEnter="RadMenuItem_MouseEnter" Loaded="RadMenuItem_Loaded" Name="cont">
                    <telerik:RadMenuItem.ItemContainerStyle>
                        <Style       TargetType="telerik:RadMenuItem">
                            <Setter Property="Header"            Value="{Binding Name}" />
                            <Setter Property="IsSeparator"            Value="{Binding IsSeparator}" />
                            <Setter Property="CommandParameter" Value="{Binding Id}"/>
                        </Style>
                    </telerik:RadMenuItem.ItemContainerStyle>
                </telerik:RadMenuItem>
                <telerik:RadMenuItem Header="Item 2" ItemsSource="{Binding Groups}"/>
    </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>

in xaml.cs:

        private void RadMenuItem_MouseEnter(object sender, MouseEventArgs e)
        {
            FillMethod();
        }


        private void FillMethod()
        {
            if (!f)
            {
                this.Dispatcher.BeginInvoke(() =>
                                                {
                                                    var viewmodel =
                                                        (MainPageViewModel)
                                                        this.Resources["ViewModel"];
                                                    viewmodel.PopupCommand.Execute(null);
                                                });
            }
        }
        private bool f = false;
        private void RadMenuItem_Loaded(object sender, RoutedEventArgs e)
        {
            f = false;
        }

in viewmodel:
        protected virtual void InvokePopup(object obj)
        {
            Groups = new List<Group>();
            Groups.Add(new Group {Name = "Loading...",Id = "---"});
            fillservice.GetGroups();
        }


        public MainPageViewModel()
        {
            fillservice = new MockFill();
            fillservice.Completeevent += FillContextMenuMethod;
            ActionCommand = new DelegateCommand<object>(InvokeAction,CanInvokeAction);
            PopupCommand = new DelegateCommand<object>(InvokePopup, CanInvokePopup);
            Groups = new List<Group>();
            Groups.Add(new Group {Name = "Loading...",Id = "---"});

        }


        private void FillContextMenuMethod(object sender, GroupsEventArgs e)
        {
            UIDispatcher.BeginInvoke(() =>
            {
                Groups = e.Groups.ToList();
            });
        }

Context menu have a bad behavior, where i change my property group where, submenu is expanding(all arrows had collapsed
for 1-3 seconds and submenu collapsed)

1 Answer, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 16 Oct 2012, 05:35 AM
Hi Andrey,

We have tried such scenario and we have set a solution for you. The problem is that if you try to remove all items in the collection, the RadContextMenu will close the popup as it doesn't have what to show. Meanwhile you are adding some items and this is causing the confusion.
In our simple application we are using Dispatcher to add items dynamically, but we remove all not needed items after we've added the new Groups.

Please check the attachment and inform us if you still have any concerns.

All the best,
Rosen Vladimirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Menu
Asked by
Andrey
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Share this question
or