Search code examples
c#.netframeworkelementfindname

No overload for method FrameworkElement.FindName takes 1 argument


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?


Solution

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

    From MSDN:

    public Object FindName(
        string name,
        FrameworkElement templatedParent
    )