CodeBehind: " /> CodeBehind: " /> CodeBehind: "/>

I am trying to have a clickable TreeViewItem.

xaml:

<TreeViewItem Header="Csv Logs"  MouseLeftButtonUp="{Binding Path=CsvLocationClick}"/>

CodeBehind:

public MouseButtonEventHandler CsvLocationClick
    { get { return OnCsvLocationClick; } }

But at runtime, I get the error:

System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.Data.Binding' threw an exception.' Line number '18' and line position '54'.'

Inner Exception
InvalidCastException: Unable to cast object of type 'System.Reflection.RuntimeEventInfo' to type 'System.Reflection.MethodInfo'.

What does this error mean? How is it fixed?

1

There are 1 best solutions below

0
mm8 On BEST ANSWER

You cannot bind to MouseLeftButtonUp. It's an event to which you are expected to hook up an event handler:

 <TreeViewItem Header="Csv Logs"  MouseLeftButtonUp="TreeViewItem_MouseLeftButtonUp"/>

Code behind:

private void TreeViewItem_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    // handle event...
}