Search code examples
c#wpf

Finding the implementation of a binding in WPF xaml


I don't know WPF much at all, but I have this piece of xaml which has the following:

<Button.InputBindings>
    <MouseBinding Gesture="LeftClick" Command="{Binding Endcommand}" />
</Button.InputBindings>

A search of the whole project finds the following:

public ICommand Endcommand { get; set; }

Endcommand = new ViewModels.DelegateCommand(o => DoEnd());

in two seperate files.

The DoEnd is also in both files.

How do I find out which one is actually being bound to. In short I have already figured this out by trial and error, but was hoping for a better solution for the future.

If I try to Peek definition in the xaml file, nothing happens and if I try to Go to definition I get an error saying "Cannot navigate to definition".

If I try "Find all references" in either of the other two files, I only get what is in the same file.


Solution

  • It's difficult to say for sure at design time what is DataContext, because it also can be changed at run time. I would just write for the Button where bindings are:

    <Button Content="{Binding}"/>
    

    So I will get the Object.ToString() value of the DataContext like a YourNammespace.YourClass