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
190
disable/enable checkboxfield depending on a property of the row viewModel
posted

Hello,

How can I set a CheckBoxField enable, or not, depending on a another property ot the row viewModel?

The autogenerateFields property is set to false.

here is FieldLayouts part.

<igDp:XamDataGrid.FieldLayouts>
	<igDp:FieldLayout>
		<igDp:TextField Name="Reference"/>
		<igDp:Field Name="Date" Format="dd/MM/yyyy"/>
		<igDp:CheckBoxField Name="IsSelected" AllowResize="False" AllowEdit="{Binding CanSelect}"/>
	</igDp:FieldLayout>
</igDp:XamDataGrid.FieldLayouts>

The datasource of the xamdatagrid is a list of MyItem class.

public sealed class MyItem : DataInfoModel //class that implement INotifyPropertyChanged,.....
{
	public string Reference{ get; set; }

	public DateTime Date{ get; set; }

	public bool CanSelect => Errors!=null && Errors.Count == 0;

	public List<String> Errors{ get; set; }

	private bool _isSelected;

	public bool IsSelected
	{
		get{ return _isSelected;}
		set
		{
			if(_isSelected==value)
				return;
			_isSelected = value;
			RaisePropertyChanged(nameof(IsSelected));

		}
	}
}

The usage of AllowEdit="{Binding CanSelect}" in the xaml does not work, why?


Thank you for any explanation.

Parents
No Data
Reply
  • 2680
    Offline posted

    Hello Christophe,

    Thank you for contacting Infragistics Developer Support!

    I have been looking into your question and I believe the FieldBinding markup extension is what you are looking for. It would allow to directly bind to a property of the ViewModel. More information about it can be found here.

    For your convenience, I am attaching a small sample demonstrating a scenario with a CheckBoxField whose AllowEdit property is bound to a property of the ViewModel. Additionally, there is a button that toggles this property’s value in order to test the binding as it changes.

    Please, test this approach on your side and let me know if it helps.

    Best regards,
    Bozhidara Pachilova
    Associate Software Developer

    8081.XDGAllowEditBind.zip

Children
No Data