I changed the InvokeMethod.cs so that the "CanXYZ" validation links to a property instead of a method of my custom class. (The CslaDataProvider uses properties too.)
private void Refresh()
{
if (_target != null && _element != null && _contentControl != null)
{
if ((bool)_element.GetValue(ManualEnableControlProperty) == false)
{
if (_target is CslaDataProvider)
{
CslaDataProvider targetProvider = _target as CslaDataProvider;
if (_element.GetValue(MethodNameProperty).ToString() == "Save")
_contentControl.IsEnabled = targetProvider.CanSave;
if (_element.GetValue(MethodNameProperty).ToString() == "Cancel")
_contentControl.IsEnabled = targetProvider.CanCancel;
if (_element.GetValue(MethodNameProperty).ToString() == "Create")
_contentControl.IsEnabled = targetProvider.CanCreate;
if (_element.GetValue(MethodNameProperty).ToString() == "Fetch")
_contentControl.IsEnabled = targetProvider.CanFetch;
if (_element.GetValue(MethodNameProperty).ToString() == "Delete")
_contentControl.IsEnabled = targetProvider.CanDelete;
if (_element.GetValue(MethodNameProperty).ToString() == "RemoveItem")
_contentControl.IsEnabled = targetProvider.CanRemoveItem;
if (_element.GetValue(MethodNameProperty).ToString() == "AddNewItem")
_contentControl.IsEnabled = targetProvider.CanAddNewItem;
}
else
{
if (_element.GetValue(MethodNameProperty) != null)
{
string targetMethodName = (string)_element.GetValue(MethodNameProperty);
string canMethodName = "Can" + targetMethodName;
//object returnValue = Csla.Reflection.MethodCaller.CallMethodIfImplemented(_target, canMethodName, null);
System.Reflection.PropertyInfo propertyInfo = Csla.Reflection.MethodCaller.GetProperty(_target.GetType(), canMethodName);
object returnValue = Csla.Reflection.MethodCaller.GetPropertyValue(_target, propertyInfo);
if (returnValue != null && returnValue is bool && (bool)returnValue == true)
_contentControl.IsEnabled = true;
else
_contentControl.IsEnabled = false;
}
}
}
}
}
Copyright (c) Marimer LLC