Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
105
Prevent user from selecting another item by binding to view model
posted

I want to prevent that user can select another item in the list controlled by a boolean property in my view model. How do I achieve this?

Parents
No Data
Reply
  • 6365
    Offline posted

    Hello,

    In order to control the selection type for the rows of the XamGrid by using a boolean property in the ViewModel class, I can suggest you use the XamGrid.SelectionSettings.RowSelection property by binding it for the boolean property with a converter. The converter will be used for converting the boolean values - true, false and null to SelectionType values - Multiple, Single, None.

    This way whenever the boolean property gets changed, the RowSelection for the XamGrid will change accordingly.

    ViewModel:

    public bool? AllowMultipleSelection { get; set; }

    XAML:

    <ig:XamGrid.SelectionSettings>
        <ig:SelectionSettings RowSelection="{Binding Source={StaticResource viewModel},
                                                        Path=AllowMultipleSelection,
                                                        Converter={StaticResource converter}}" />
    </ig:XamGrid.SelectionSettings>

    Code-behind:

    object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var allowMultipleSelection = value as bool?;
               
        switch(allowMultipleSelection)
        {
            case true:  return SelectionType.Multiple;
            case false: return SelectionType.Single;
            case null:  return SelectionType.None;
            default:    return SelectionType.None;
        }           
    }

    I have attached a sample application that demonstrates the approach from above.

    If you have any questions, please let me know.

    XamGrid_sample.zip
Children