3

Hey,

short question:

I want to notify my ui, so my guard method is invoked once again.. But unfortunately I get an syntax-error using this statement:

NotifyOfPropertyChange(() => CanLogin);

My class inherits PropertyChangedBase.

The error message:

The type arguments for method 'void Calidburn.Miro:PropertyChangedBase.NotifyOfPropertyChange<TProperty>(Expression<Func<TProperty>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Do I miss some overload or is something else wrong? What else could be the problem?

Selman Genç
  • 100,147
  • 13
  • 119
  • 184
Jannik
  • 2,310
  • 6
  • 32
  • 61

1 Answers1

2

Based on the code you posted in your comment, I think your problem is that the NotifyPropertyChanged method is expecting you to pass a property, rather than a method.

So you'd want something like:

public bool CanLogin 
{ 
    get
    {
        return !string.IsNullOrEmpty(Ip) && !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Port); 
    }
}

I was going to write something about Expression<Func<TProperty>> to help explain the error message, but this answer does a fantastic job: Why would you use Expression<Func<T>> rather than Func<T>?

Community
  • 1
  • 1
Chris
  • 8,268
  • 3
  • 33
  • 46
  • Thank you Chris. :) Do you have any idea, why I never saw this solution? I mean, all the samples I saw on the internet were showing methods instead of properties :( – Jannik Feb 02 '14 at 00:12
  • Hey, I'm actually not sure, I tried looking through the docs to see where you might find that out, but aside from http://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions (search for `CanSayHello`) there isn't a huge mention of it. I've often made mistakes like making the property a field, or making it a method and then finding problems, so it's a common error =D – Chris Feb 02 '14 at 00:18
  • What is slightly odd, is that if I create a method, rather than a property, I get a slightly different error to yours =O – Chris Feb 02 '14 at 00:20
  • FYI: I havent started the program, I have just pointed my cursor at the underlined statement, so maybe thats why your msg differs from mine. – Jannik Feb 02 '14 at 11:29
  • I get messages along the lines of `Cannot convert lambda expression to type 'string' because it is not a delegate type`, glad it's fixed though =D – Chris Feb 02 '14 at 12:01