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?
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.
Thanks Tacho for your answer but I think I did not explained clearly what I want to achieve.
I do not want to switch between single or multiple selection. The selection type should always be SelectionType.Single. If the boolean property is set to true, the user should be able to select another (not an additional) item. But if the boolean property is set to false, the user shall not be able to change the selected item.