RadContextMenuItem doesn't obey .IsEnabled

17 posts, 0 answers
  1. bc3tech
    bc3tech avatar
    14 posts
    Member since:
    Oct 2011

    Posted 23 Dec 2011 Link to this post

    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.
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 30 Dec 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Eric Schoenholzer
    Eric Schoenholzer avatar
    138 posts
    Member since:
    Mar 2004

    Posted 17 Feb 2012 Link to this post

    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)
  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 21 Feb 2012 Link to this post

    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 >>
  6. Eric Schoenholzer
    Eric Schoenholzer avatar
    138 posts
    Member since:
    Mar 2004

    Posted 22 Feb 2012 Link to this post

    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
  7. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 23 Feb 2012 Link to this post

    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 >>
  8. Eric Schoenholzer
    Eric Schoenholzer avatar
    138 posts
    Member since:
    Mar 2004

    Posted 02 Mar 2012 Link to this post

    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
  9. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 06 Mar 2012 Link to this post

    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 >>
  10. Pat
    Pat avatar
    31 posts
    Member since:
    Mar 2009

    Posted 15 Mar 2012 Link to this post

    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
  11. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 19 Mar 2012 Link to this post

    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 >>
  12. Kanishk
    Kanishk avatar
    11 posts
    Member since:
    Apr 2012

    Posted 28 May 2012 Link to this post

    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"/>

  13. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 28 May 2012 Link to this post

    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 >>

  14. Kanishk
    Kanishk avatar
    11 posts
    Member since:
    Apr 2012

    Posted 28 May 2012 Link to this post

    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"/>

  15. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 28 May 2012 Link to this post

    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 >>

  16. Kanishk
    Kanishk avatar
    11 posts
    Member since:
    Apr 2012

    Posted 28 May 2012 Link to this post

    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!
  17. Kanishk
    Kanishk avatar
    11 posts
    Member since:
    Apr 2012

    Posted 28 May 2012 Link to this post

    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) { }
        }
  18. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 29 May 2012 Link to this post

    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 >>

Back to Top
DevCraft banner