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

RadMenuItem IsEnabled Property bound to GridView SelectedItems Collection

5 Answers 144 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Rupert Henson
Top achievements
Rank 1
Rupert Henson asked on 11 May 2011, 04:31 PM
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.

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 16 May 2011, 09:40 AM
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
0
Rupert Henson
Top achievements
Rank 1
answered on 17 May 2011, 12:08 PM
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.
0
Hristo
Telerik team
answered on 17 May 2011, 02:59 PM
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
0
Fernando
Top achievements
Rank 1
answered on 01 Jul 2011, 09:37 PM
Hi there Hristo!

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

Cheers!
Fernando.-
0
Hristo
Telerik team
answered on 04 Jul 2011, 07:27 AM
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
Tags
Menu
Asked by
Rupert Henson
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Rupert Henson
Top achievements
Rank 1
Fernando
Top achievements
Rank 1
Share this question
or