Hello all
I have been working on a WPF app, and it's 99% finished, but I have a problem.
When I attempt to update a DataGrid after a database delete operation, I get the following, exception:
Non-static method requires a target
The Exception is happening inside the ViewModelBase when the View Model attempts to update the view, code:
public class ViewModelBase : INotifyPropertyChanged
{
public ViewModelBase()
{
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Private Methods
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
The rest of the time the app runs as expected, with the code section causing no problems. The data comes back from the database without any problems.
Has anyone got any ideas ??
Thanks in advance.
Baxter-P
OK,
Thanks for the replies.
The comments about details are very fair, so, here is the property I am binding to:
private ObservableCollection<UserData> userData = new ObservableCollection<UserData>();
public ObservableCollection<UserData> UserData
{
get
{
return userData;
}
set
{
userData = value;
RaisePropertyChanged("UserData");
}
}
Also here is the class for the data:
public class UserData
{
public UserData(int id, string userName)
{
this.ID = id;
this.UserName = userName;
}
public int ID { get; set; }
public string UserName { get; set; }
}
Standard stuff. Also here is a screen shot of my DataGrid XAML code:
http://s30.postimg.org/rftcsp01d/xaml.png[
^]
Also here is the code where the excepetion is caused:
private void DeleteUserCommandExecute(Object parameter)
{
WPFMessageBox messageBox = new WPFMessageBox("Delete ?", "Are you sure you want to DELETE user '" + userName + "' ?", MessageBoxType.YesNo);
if (messageBox.Answer != MessageBoxDecision.Yes)
return;
try
{
lookUpContext.DeleteUser(userID);
lookUpContext.SaveChanges();
RemoveAllUserDivisions();
PopulateUserDivisions();
GetUserData();
UserName = String.Empty;
AllowUIToUpdate();
}
catch (Exception ex)
{
WPFMessageBox errorMessageBox = new WPFMessageBox("Error", "Error DELETING data - " + ex.Message, MessageBoxType.OK);
}
}
Also, the call to the database:
private void GetUserData()
{
lookUpContext = new JMLookupEntities();
var UserDataLocal = (from data in lookUpContext.JMUsers.ToList()
select new UserData(data.ID, data.UserName)).ToList();
UserData = UserDataLocal.ToObservableCollection();
}
The event causing the exception is the DeleteUserCommand execute event. The exception occurs when I try to update the 'dgUsers' datasource property 'UserData' shown above. The code block to update the view is called multiple times before the problem occurs, with no problems.
I really do not understand this problem, and I have tried everything.
I am using WPF 4.5, and EF 6.
Thanks Again,
Baxter-P