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

Menus and MVVM

11 Answers 346 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Corrado Cavalli
Top achievements
Rank 2
Corrado Cavalli asked on 19 Aug 2009, 07:24 PM
Any chance to have a Command property on RadMenuItem? that would help M-V-VM development a lot.

Thanks
Corrado

11 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 21 Aug 2009, 07:53 AM
Hello Corrado,

There is no ICommandSource interface in Silverlight, yet, hence RadMenuItem does not have a Command/CommandParameter/CommandTarget properties.

On the other hand, we provide our own implementation for routed commands, that include the interface, but it was first intended only for internal use and that's why most of the controls do not implement it. I am currently updating RadMenuItem and most probably it will get the Command property with the internal build next week.

Greetings,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Neal Sanche
Top achievements
Rank 1
answered on 30 Oct 2009, 08:16 PM
Any updates on this since? I would also love to be able to bind ICommand to a property on the RadContextMenu. In the meantime I am trying to wire up an attached behavior, but I'm not quite sure how that's going to work yet.

-Neal
0
Valeri Hristov
Telerik team
answered on 02 Nov 2009, 07:50 AM
Hi Neal,

RadMenu/RadContextMenu for Silverlight and WPF will provide ICommandSource implementation as of Q3 2009 which will be released this week.

Regards,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Neal Sanche
Top achievements
Rank 1
answered on 02 Nov 2009, 08:43 PM
Thanks! That's great, I can hardly wait.

-Neal
0
Neal Sanche
Top achievements
Rank 1
answered on 04 Nov 2009, 04:15 PM
Just a follow-up. I have upgraded to the Q3 release and have tried doing a binding with a RadMenuItem using its Command property to a property on my ViewModel class (of type ICommand) and it works! This is a great new feature of the Q3 release, and isn't mentioned very much in the release notes (on my initial skim of them).

Here's my XAML:

<Grid Height="39" MinWidth="90"
   <Controls:RadContextMenu.ContextMenu> 
      <Controls:RadContextMenu> 
         <Controls:RadMenuItem Command="{Binding DeleteQueryCommand}" Header="Delete Query"/> 
      </Controls:RadContextMenu> 
   </Controls:RadContextMenu.ContextMenu> 
   <TextBlock Text="Query 1"/> 
</Grid> 

I've been following a DelegateCommand pattern in my view model classes, and the code for this command looks something like the following:

        #region DeleteQuery Command 
 
        private DelegateCommand m_deleteQueryCommand; 
 
        public ICommand DeleteQueryCommand 
        { 
            get 
            { 
                if (m_deleteQueryCommand == null) m_deleteQueryCommand = new DelegateCommand(DeleteQuery, DeleteQueryCanExecute); 
                return m_deleteQueryCommand; 
            } 
        } 
 
        private void DeleteQueryCanExecuteChanged() 
        { 
            m_deleteQueryCommand.RaiseCanExecuteChanged(); 
        } 
 
        private bool DeleteQueryCanExecute() 
        { 
            return true
        } 
 
        private void DeleteQuery() 
        { 
            QueryDeleted.Fire(this, EventArgs.Empty); 
        } 
        #endregion 

I've even tested that the menu item is grayed out when the DeleteQueryCanExecute method returns false!

Thanks for the great work!

-Neal
0
Kevin Finke
Top achievements
Rank 1
answered on 13 Nov 2009, 06:32 PM
This is exactly what I want!

But where oh where is the rest of the command framework?  Where is DelegateCommand defined?  I seem to be missing something!
0
Valeri Hristov
Telerik team
answered on 17 Nov 2009, 12:56 PM
Hi Kevin,

Our command framework was designed to be used the same way as the standard WPF commands, hence there is no delegate commands, etc. It was first developed to provide a compatibility layer for the RadScheduler port to Silverlight, later we began using it in other controls. The ICommandSource implementation in RadMenuItem is standard and will work with any command framework, such as Prism for example.

Sincerely yours,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
bohebolo
Top achievements
Rank 1
answered on 07 Sep 2010, 11:43 AM
Is it possible to use command with dynamic data binding on RadMenu?
And if yes, how to do that?
0
bohebolo
Top achievements
Rank 1
answered on 07 Sep 2010, 02:59 PM
I've got the answer now, and yes it can actually.
Just bind Command & CommandParameter properties in ContainerBindingCollection.
EDIT: layoutRoot is a grid in my view which it's datacontext is bound to my viewmodel.

<telerik:HierarchicalDataTemplate x:Key="mainMenuTemplate" ItemsSource="{Binding SubItems}">
    <telerik:ContainerBinding.ContainerBindings>
        <telerik:ContainerBindingCollection>
            <telerik:ContainerBinding PropertyName="Icon" Binding="{Binding Icon}" />
            <telerik:ContainerBinding PropertyName="Command" Binding="{Binding
                      DataContext.MenuOpenCommand, ElementName=layoutRoot, Mode=OneWay}"
/>
            <telerik:ContainerBinding PropertyName="CommandParameter" Binding="{Binding}" />
        </telerik:ContainerBindingCollection>
    </telerik:ContainerBinding.ContainerBindings>
    <TextBlock Text="{Binding Text}" />
</telerik:HierarchicalDataTemplate>
0
Kaloyan
Telerik team
answered on 07 Sep 2010, 03:12 PM
Hello bohe,

The approach taken is the correct one. Let us know if you are facing any further issues.

Kind regards,
Kaloyan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Hicham
Top achievements
Rank 1
answered on 23 Mar 2012, 05:19 PM
Hi,
I wanna send a commandParameter to a command, but i get always null for the parameter:

 <telerik:RadContextMenu.ContextMenu>
                                <telerik:RadContextMenu>
                                    <telerik:RadContextMenu.Items>
                                        <telerik:RadMenuItem Header="Fonctions Mathématiques"  >
                                            <telerik:RadMenuItem Header="INT()" Command="{Binding TestCommand}" CommandParameter="{Binding ElementName=txtFormula}"/>
                                            <telerik:RadMenuItem Header="AVERAGE()" />
                                            <telerik:RadMenuItem Header="ROUND()" />
                                            <telerik:RadMenuItem Header="ROUNDUP()" />
                                            <telerik:RadMenuItem Header="ROUNDDOWN()" />
                                        </telerik:RadMenuItem>
                                        <telerik:RadMenuItem Header="Operateurs" >
                                            <telerik:RadMenuItem Header="&lt;" />
                                            <telerik:RadMenuItem Header="&gt;" />
                                            <telerik:RadMenuItem Header="&lt;&gt;" />
                                        </telerik:RadMenuItem>
                                    </telerik:RadContextMenu.Items>
                                </telerik:RadContextMenu>
                            </telerik:RadContextMenu.ContextMenu>


the command :

 string testCommand = "";
        public ICommand TestCommand
        {
            get
            {
                return new RelayCommand<System.Windows.Controls.RichTextBox>((o) =>
                {
                    if (o != null)
                        testCommand = o.ExtentWidth.ToString();
 
 
                    
                });
            }
        }


do you have any idea about this issue?

thanks.
Tags
Menu
Asked by
Corrado Cavalli
Top achievements
Rank 2
Answers by
Valeri Hristov
Telerik team
Neal Sanche
Top achievements
Rank 1
Kevin Finke
Top achievements
Rank 1
bohebolo
Top achievements
Rank 1
Kaloyan
Telerik team
Hicham
Top achievements
Rank 1
Share this question
or