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

RadContextMenuItem doesn't obey .IsEnabled

16 Answers 174 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
bc3tech
Top achievements
Rank 2
bc3tech asked on 23 Dec 2011, 09:40 PM
My XAML:
<Grid Grid.Row="1"
      Margin="12,0,12,0">
    <ListBox x:Name="ProfileList"
             DoubleTap="ProfileList_DoubleTap"
             ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid Tag="{Binding}">
                    <telerik:RadContextMenu.ContextMenu>
                        <telerik:RadContextMenu Opening="ContextMenu_Opening"
                                                Background="{StaticResource PhoneContrastBackgroundBrush}">
                            <telerik:RadContextMenuItem x:Name="PinToStart"
                                                        IsEnabled="False"
                                                        Content="Pin to Start"
                                                        Tap="PinToStart_Tap" />
                        </telerik:RadContextMenu>
                    </telerik:RadContextMenu.ContextMenu>

Even though IsEnabled is explicity let to False here, I can still click the menu item. If I set .IsEnabled in codebehind, it doesn't change anything either.

16 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 30 Dec 2011, 03:14 PM
Hello Brandon,

Thank you for reporting this!

We verified the isssue and we will release an internal build next week with a fix for the issue. I added 1000 Telerik points to your account.

Kind regards, Valentin.Stoychev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Eric Schoenholzer
Top achievements
Rank 2
answered on 17 Feb 2012, 05:00 PM
I have the same problem, but while using a Command.

For the first time, the state is reflected correct -> CanExecute == true -> Menu enabled or CanExecute == false-> Menu disabled.

But when I open the menu the second time and CanExecute returns false, then menu is still enabled.

Shouldn't it reflect the correct state?

Thanks
Eric

(V2012.1.214.2040)
0
Todor
Telerik team
answered on 21 Feb 2012, 04:50 PM
Hi Eric,

Yes, you are right that when the return value of CanExecute changes, this should be reflected in the ContextMenuItem. We have already fixed this and you can download the fix with our latest internal build:
RadControls_for_WindowsPhone_2012_1_0221_DEV_hotfix, which is available from the Downloads section of your account.

Thank you for your time. I have added 1000 points to your account for bringing this to our attention.

Kind regards,
Todor
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Eric Schoenholzer
Top achievements
Rank 2
answered on 22 Feb 2012, 04:13 PM
Hi,
Was able to get the correct hotfix.

But it seems there is a new problem.
When I used the command as this:
Command="{StaticResource DeleteCommand}" CommandParameter="{Binding}" 

the parameter in CanExecute is always null.

Command="{StaticResource DeleteCommand}" 
Without specifiying the parameter, I get the param of type RadDataBoundListBoxItem.
But now I'm getting an error when I'm calling the delegate/event CanExecuteChanged:

System.NullReferenceException was unhandled
  Message=NullReferenceException
  StackTrace:
       at Telerik.Windows.Controls.RadContextMenu.GetCurrentManipulationSource()
       at Telerik.Windows.Controls.RadContextMenuItem.GetActualCommandParameter()
       at Telerik.Windows.Controls.RadContextMenuItem.UpdateIsEnabled()
       at Telerik.Windows.Controls.RadContextMenuItem.OnCommandCanExecuteChanged(Object sender, EventArgs e)
       at MyApp.Helper.CommandBase`1.OnCanExecuteChanged(EventArgs e)


So, I think something is mixed up now. (see also your example here: http://www.telerik.com/community/forums/windows-phone/trial-feature-reminder/reminder-and-commands.aspx#1997325

Thanks
Eric
0
Victor
Telerik team
answered on 23 Feb 2012, 12:29 PM
Hello Eric,

 Thank you for writing.
I managed to reproduce the exception you described and the issue has been fixed. The new dlls will be available for download as an internal build later today.
Please write again if you need further assistance.

Regards,
Victor
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Eric Schoenholzer
Top achievements
Rank 2
answered on 02 Mar 2012, 11:29 PM
Hi,

I have still problems with the latest hotfix version (301).

I defined the ContextMenuItem for a RadJumpList like this:

    <telerikPrimitives:RadContextMenuItem Content="Download" Command="{StaticResource DownloadCommand}" CommandParameter="{Binding}"/>

So I expect as parameter for CanExecute a object of type RadDataBoundListBoxItem
But the param is always null.

Could you tell me why the param is always null? I thought this was fixed.

Thanks
Eric
0
Victor
Telerik team
answered on 06 Mar 2012, 02:22 PM
Hello Eric,

 Thank you for writing.
In order for the command parameter to be a RadDataBoundListBoxItem, the CommandParameter property should not be set. When it is not set, the context menu should automatically pass the visual item as command parameter.

Please write again if you need further assistance.

All the best,
Victor
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Pat
Top achievements
Rank 1
answered on 15 Mar 2012, 12:15 PM
I am currently using build 2012.1.313.2040 and it still seems that  aRadContextMenuItem is still acting correctly if I set IsEnabled to false. I have set it on the XAML and in the code behind when the the menu Opening call is made.

Pat
0
Victor
Telerik team
answered on 19 Mar 2012, 06:17 PM
Hi Brandon,

Thank you for writing.
We decided that the IsEnabled property should be controlled from one point only. This point is determined according to whether there is a command set or not. If a command is set, the command will always have priority and it will be responsible for managing the IsEnabled property. This can be done with the CanExecute() method that every command has. If CanExecute() returns false, the menu item will be disabled, if it returns true, the item will be enabled. If no command is set, the IsEnabled property will be available through XAML or C#.

Please write again if you have other questions.
 
Kind regards,
Victor
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Kanishk
Top achievements
Rank 1
answered on 28 May 2012, 03:13 PM
Hi,

I am having just a tapped event on RadContextMenuItem (and not a command), but the IsEnabled property is not being respected. I dont want to write a command for achieving the enabled/disabled state. Can you please look into this?

<

 

 

telerikPrimitives:RadContextMenuItem Content="pin to start" Tapped="Pin_Clicked" IsEnabled="False"/>

0
Victor
Telerik team
answered on 28 May 2012, 03:28 PM
Hi Kanishk,

Thanks for writing.
The Tapped event will be marked as obsolete from this release and will removed subsequently because since the Mango update, a system Tap event was introduced. Please use the Tap event instead.

Greetings,
Victor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Kanishk
Top achievements
Rank 1
answered on 28 May 2012, 03:38 PM
Hi,

As suggested, I have moved to Tap event instead of Tapped event, however setting IsEnabled=False is still not being respected. Please resolve this or unfortuantely I will have to move back to silverlight context menus.

<

 

 

telerikPrimitives:RadContextMenuItem Content="pin to start" Tap="Pin_Clicked" IsEnabled="False"/>

0
Victor
Telerik team
answered on 28 May 2012, 04:01 PM
Hi Kanshik,

Thank you for the feedback.
This is a bug in the context menu and it will be fixed in the upcoming Q2 2012 release (next week on June 6-th).
Please write again if you have more feedback to share or if you need assistance with our controls.
Your Telerik points have been updated.

All the best,

Victor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Kanishk
Top achievements
Rank 1
answered on 28 May 2012, 04:08 PM
Thanks you for your prompt replies. I will try to implement it via Command (suggested in this thread) as I can't wait till next week. Telerik controls are nice and I have moved my apps from silverlight toolkit controls to telerik rad controls. Don't want to bring back silverlight toolkit controls just because of ContextMenu.

Also thank you for working on a fix in the upcoming release!
0
Kanishk
Top achievements
Rank 1
answered on 28 May 2012, 06:54 PM
Here is a quick workaround in case anyone is interested. It does involve implementing ICommand, but to a very minimal level (only for enabling/disabling) and allows handling of the Tap event as normal

Instead of doing this from code behind (assuming 0th item needs to be enabled/disabled):
((RadContextMenuItem)menu.Items[0]).IsEnabled = <condtion> ? true : false;

Do this:
((RadContextMenuItem)menu.Items[0]).Command = <condition> ? null : new NonExecutableCommand();
where  NonExecutableCommand is implemented as:
public class NonExecutableCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return false;
        }
 
        public event System.EventHandler CanExecuteChanged;
        public void Execute(object parameter) { }
    }
0
Victor
Telerik team
answered on 29 May 2012, 08:15 AM
Hello Kanishk,

Thank you for understanding and for posting the workaround, other people will definitely find it useful if they run into this issue.

Kind regards,
Victor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ContextMenu
Asked by
bc3tech
Top achievements
Rank 2
Answers by
Valentin.Stoychev
Telerik team
Eric Schoenholzer
Top achievements
Rank 2
Todor
Telerik team
Victor
Telerik team
Pat
Top achievements
Rank 1
Kanishk
Top achievements
Rank 1
Share this question
or