1

Is there way to get name of property in XAML?

I found there is no support for nameof in XAML.

Something serving like this:

<i:InvokeCommandAction 
Command="{Binding
    Source={StaticResource SomeViewModel},
    Path=SomeICommandImplementation}" 
CommandParameter={Binding 
    Source={StaticResource SomeViewModel},
    Path=SomeProperty, 
    GetNameOf=True}" />
Yarl
  • 728
  • 1
  • 7
  • 26
  • 2
    Did you read their response? "*We have reviewed this and we will not be able to complete this suggestion in the foreseeable future*". So what is your question? – Clemens Jun 17 '17 at 17:50

1 Answers1

2

Is there way to get string name of property in XAML.

No, there isn't. XAML is a markup language and it has no nameof operator defined.

What you could do is to try to implement your own custom InvokeCommandAction.

Create a class that derives from System.Windows.Interactivity.TriggerAction<DependencyObject>, add the properties of InvokeCommandAction (it is sealed so you cannot derive from it) and another GetNameOf property to it and then override the Invoke method to use the nameof operator.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • mm8: I conceptually and partially understand your proposition but my properties originates in view model. If I define them at TriggerAction they would exists twice. But basically in System.Windows.Interactivity namespace I can find solution since I have information that passing UI elements to its members is MVVM okay. – Yarl Jun 19 '17 at 19:26
  • 1
    You are not supposed to define the view model properties in your custom TriggerAction. You should define the Command, CommandParameter and GetNameOf target properties. – mm8 Jun 20 '17 at 08:59