No overload for method FrameworkElement.FindName takes 1 argument

199 views Asked by At

So I've got some code:

var columnHeader = (e.OriginalSource as GridViewColumnHeader);   
var temp = columnHeader.Template.FindName("Up");

When I click my GridViewColumnHeader I run this code. But the line columnHeader.Template.FindName("Up") is raising the error: No overload for method 'FindName' takes 1 arguments

But what makes this different from any other question is the Microsoft documentation for FrameworkElement.FindName clearly shows a method that takes one argument:

public Object FindName( string name )

Parameters name Type: System.String

The name of the requested element.

Return Value Type: System.Object

The requested element. This can be null if no matching element was found.

So why does my compiler raise this error?

2

There are 2 answers

0
Yuval Itzchakov On BEST ANSWER

GridViewColumnHeader.Template is a ControlTemplate, which inherits from FrameworkTemplate, not FrameworkElement:

From MSDN:

public Object FindName(
    string name,
    FrameworkElement templatedParent
)
0
Drew Morgan On

Template has the type ControlTemplate, which inherits FrameworkTemplate. The latter takes two parameters, not one.