Error: The name 'FindName' does not exist in the current context in my new Class

230 Views Asked by At

I'm currently creating a new UWApp in C# using Visual Studio 2017. after creating a new Class that will handle all the display of Xaml content.

I transferred a function containing this line of code:

...

Image imgObj = (Windows.UI.Xaml.Controls.Image)FindName("myTopImage");

...

to the new Class but FindName is highlighted in Red with this error message:

The name 'FindName' does not exist in the current context

I'm not sure why FindName is working well in the MainClass and not in the new Class. I've done this before in other App without any issues.

thanks for you time.

1

There are 1 best solutions below

0
Erix On

What I end up doing to solve the problem:

  1. add a new Content page (xaml+cs)
  2. transferred all my existing xaml & code from the Main to the new page

This way all the controls are out of the Main page and accessible from the new page class. I should have done this from the beginning.