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

Enable/Disable button according Items count in XAML

1 Answer 1244 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
ENTERPRISE INTERNATIONAL SAS asked on 14 Mar 2011, 10:29 PM
Hi!


I would like to know how to enable a button when items.count > 0 and disable it when items.count == 0 but into XAML using binding. I did this:

<Button x:Name="btnAceptar" Content="Aceptar" Command="{Binding GrabarCommand}" IsEnabled="{Binding ElementName=grdGrid, Path=Items.Count, Converter={StaticResource ConvertidorHabilitacionItemsGrid}, Mode=OneWay}" >

converter is:

public class ConvertidorHabilitacionItemsGrid : IValueConverter
 {
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
     {
         return !((int)value == 0);
     }
 
     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
     {
         throw new NotImplementedException();
     }
 }


But it not works

thanks

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 16 Mar 2011, 02:41 PM
Hello Ramiro,

May I suggest you yet another approach ? You may use the ObservableItemCollection for the source of the grid and handle its CollectionChanged event. Once the count of the items is equal to zero, you may disable the corresponding button. I am sending you a sample project illustrating this approach. Let me know whether it suits your needs.  
 

Best wishes,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or