RadMenuItem IsEnabled Property bound to GridView SelectedItems Collection

6 posts, 0 answers
  1. Rupert Henson
    Rupert Henson avatar
    8 posts
    Member since:
    Jul 2009

    Posted 11 May 2011 Link to this post

    Hi,

    I'm currently converting over a row of standard Silverlight Buttons at the bottom of our panels, to become a RadMenu (with RadMenuItem's for buttons). I'm using v2011.1.419.1040 of the controls.

    Using the Silverlight standard built in Button I was able (rightly or wrongly) to use a binding for IsEnabled so that the "View Details" button would only be enabled when a RadGridView had 1 or more selected items.

    However, when I try this using RadMenuItem it works initially disabled (nothing selected), but once a Selection in the GridView has been made then unselected (eg. using Ctrl key) the RadMenuItem stays enabled forever.

    Example:-

    <

     

     

    telerik:RadGridView x:Name="RadGridView1" Grid.Row="0" Loaded="RadGridView_Loaded" AutoGenerateColumns="True" />

     


    <

     

     

    Button Content="View Detail" Grid.Row="1" IsEnabled="{Binding ElementName=RadGridView1,Path=SelectedItems.Count}" />

    Whereas the following does not operate in the same way.

     

     

     

     

     

    <telerik:RadMenu ClickToOpen="True" Orientation="Horizontal" VerticalAlignment="Center" Grid.Row="2">

     

     

     

     

     

     

     

     

     

     

     

     

    <telerik:RadMenuItem Header="View Detail" IsEnabled="{Binding ElementName=RadGridView1,Path=SelectedItems.Count}" />

     

     

     

     

     

     

     

     

     

     

     

     

    </telerik:RadMenu>

     

     

     

     

     

     


    What should be my method for achieving this with RadMenuItem? NB. I've tried hooking up to the SelectionChanged event of the RadGridView to check for SelectedItems.Count and Enable/Disable the button as necessary, but I've found some circumstances where the deselection occurs and the SelectionChanged event does not get fired.

    How can I guarantee that my "View Detail" RadMenuItem cannot be clicked unless there are Selected Items? I'm hoping for a declarative Binding solution rather than having to put lines of checking code in every RadMenu click event to see if it's been clicked when nothing is currently selected in the RadGridView.....

    Regards,

    Rupert Henson.
    Innovation Group.

  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 16 May 2011 Link to this post

    Hi Rupert,

    You should specify Binding with Mode=TwoWay otherwise the framework will clear it once we set local value to IsEnabled Property.
    <telerik:RadMenuItem Header="View Detail" IsEnabled="{Binding ElementName=RadGridView1, Path=SelectedItems.Count, Mode=TwoWay}" /> 

    Let us know if you need more information.

    Greetings,
    Hristo
    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
  3. DevCraft banner
  4. Rupert Henson
    Rupert Henson avatar
    8 posts
    Member since:
    Jul 2009

    Posted 17 May 2011 Link to this post

    Hi Hristo,

    Thanks - that worked a treat.

    A strange fix though -  why would I want to be using Mode=TwoWay to fix it - attempting to store back the IsEnabled Boolean Flag value into the GridView's SelectedItems.Count field (?). No matter.....

    Thanks for the tip I will use it throughout our project.

    Regards,

    Rupert.
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 17 May 2011 Link to this post

    Hi Rupert,

    The problem is that we are setting IsEnabled from code based on the ICommand CanExecute result and when property is bound (without using TwoWay) binding is lost when local value is set.
    This is a problem in the framework - there is no way to set value to a dependency property without losing the binding.

    In your code you don't set Command property but we still set IsEnabled which clear the binding.
    I hope that in Silverlight 5 there will be way to resolve this without using TwoWay binding.

    Kind regards,
    Hristo
    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
  6. Fernando
    Fernando avatar
    1 posts
    Member since:
    Sep 2008

    Posted 01 Jul 2011 Link to this post

    Hi there Hristo!

    What about using SetValue(DProperty, value) instead of doing property = value?

    Cheers!
    Fernando.-
  7. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 04 Jul 2011 Link to this post

    Hi Fernando,

    Property=value internally do this.SetValue(DP, value).
    So this will not help. This is fundamental issue that is solved in .Net Framework 4 with new method - this.SetCurrentValue(Dp, value). This method will set current value on a DP without removing one way bindings but it is still unavailable in Silverlight.

    Greetings,
    Hristo
    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
Back to Top
DevCraft banner