Hi there
I’m using WPF Infragistic 2011 V2 XamDatagrid. The application is based on MVVM. I need to prevent some records from being deleted based on a Boolean property (IsReadOnly) in my model.
I have tried to bind AllowDelete property either to a bool in my model or a to property in a VM:
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" AllowDelete="{Binding ....." />
</igDP:XamDataGrid.FieldLayoutSettings>
But in both cases I'm getting runtime error "Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path= "
How can I stop a user from deleting data rows selectively without using code behind?
RegardsBoris
If you are using MVVM you want to take a different approach for handling deletes. Don't rely on the grid to do it for you. Check out the attached sample.
Not sure about popping up a Message box from VM... but how about deriving from XamDataGrid and adding AllowDelete DependencyProperty?
public class XamDataGridEx : XamDataGrid{
public static readonly DependencyProperty AllowDeleteProperty = DependencyProperty.Register("AllowDelete", typeof(bool),
typeof(XamDataGridEx), new UIPropertyMetadata(false, OnAllowDeletePropertyChanged));
private static void OnAllowDeletePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
XamDataGridEx control = source as XamDataGridEx;
bool value = (bool)e.NewValue;
control.FieldLayoutSettings.AllowDelete = value;
}
public bool AllowDelete
get { return (bool)GetValue(AllowDeleteProperty);}
set { SetValue(AllowDeleteProperty, value);}