Dataform submit and cancel buttons
I'm having trouble with the Commit and Cancel buttons in the dataform for Silverlight. At first I couldn't figure out why the Cancel button was not enabled when the user clicked edit. After some research I found this was because the object was not IEditableObject. That sorted the cancel button but now the Commit button has decided to become enabled, where it wasn't before, even after the value has changed.
My question is, how do I get it is to be enabled?
XAML:
<dataFormToolkit:DataForm CurrentItem="{Binding ViewModel, ElementName=AccountPage, Mode=TwoWay}" CommandButtonsVisibility="{Binding ViewModel.CommandButtonsVisibility, ElementName=AccountPage, Mode=TwoWay}" AutoEdit="False" AutoGenerateFields="False" AutoCommit="False">
<dataFormToolkit:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<dataFormToolkit:DataField Label="Organisation Name">
<TextBox Text="{Binding Customer.Name, Mode=TwoWay}"/>
</dataFormToolkit:DataField>
</StackPanel>
</DataTemplate>
</dataFormToolkit:DataForm.EditTemplate>
</dataFormToolkit:DataForm>
XAML.cs:
public partial class Account : Page
{
public VMAccount ViewModel { get; set; }
public Account()
{
InitializeComponent();
}
// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ViewModel = new VMAccount(Global.Client.CurrentPerson.Customer);
}
}
VMAccount:
public class VMAccount : VMBase, IEditableObject
{
public VMAccount(Customer customer)
{
Customer = customer;
}
private Customer m_oCustomer;
public Customer Customer
{
get { return m_oCustomer; }
set
{
if (m_oCustomer != value)
{
m_oCustomer = value;
OnPropertyChanged("Customer");
}
}
}
public event EventHandler<AsyncResultArgs> SaveCustomerSuccess;
public event EventHandler<AsyncResultArgs> SaveCustomerFailure;
#region IEditableObject Members
public void BeginEdit()
{
Customer.PropertyChanged += new PropertyChangedEventHandler(OnCustomerPropertyChanged);
Customer.ContactInfo.PropertyChanged += new PropertyChangedEventHandler(OnCustomerPropertyChanged);
}
public void CancelEdit()
{
(Customer as IRevertibleChangeTracking).RejectChanges();
(Customer.ContactInfo as IRevertibleChangeTracking).RejectChanges();
}
public void EndEdit()
{
if (Customer.HasChanges)
{
Global.Client.MainContext.SubmitChanges((lo) =>
{
HandleResult("Save Customer", lo, true, SaveCustomerSuccess, SaveCustomerFailure);
}, null);
}
}
#endregion
private void OnCustomerPropertyChanged(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged("Customer");
}
}
VMBase:
public class VMBase : INotifyPropertyChanged
{
protected virtual void OnPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
I put in the 'OnCustomerPropertyChanged' event handler to see if I could force the dataform to acknoledge the Customer property has changed but it doesn't make a difference, even though the event is fir开发者_StackOverflowing. I've tried removing the IEditableObject to confirm that this is the problem...
public class VMAccount : VMBase//, IEditableObject
...
Thanks for any help.
EDIT: I should add that Customer is an RIA Entity
So it turns out I was trying to edit a nested object which can't be done until RIA toolkit SP1 is released. Thanks.
You problem can be similar at question Silverlight 3 Dataform Commit Button not activating
Please, revise this response
I had the same isue using silverlight 4 and RIA serivces.
I resolved installing the WCF RIA Services Service Pack 1 and re-installing the WCF RIA Services Toolkit for WCF RIA Services SP1.
This two installer can be found at: http://www.silverlight.net/getstarted/riaservices/
Direct link to WCF RIA Services SP 1: http://go.microsoft.com/fwlink/?LinkId=205085 Direct link to WCF RIA Services toolkit for WCF RIA Services SP1: http://go.microsoft.com/fwlink/?LinkID=205088
精彩评论