Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How to access an object (e.g. entry) on a page via object-reference?

$
0
0

Hi all

On my registration-page, I have various entry-controls.
The entry-controls are based (instances) on my own class (with description-label, entry, error-label, some additional methods, including a setfocus()-method, to set the focus to the entry).

If the user tap the “Register”-button, the values are checked.
If something is missing, there are alerts showed and the page is scrolled to the first missing input.

Now, I want also to set the focus to the first control, that have missing input.
As I don’t want to implement a “huge switch” (if control = “xx”, xx.focus, if control = “yy”, yy.focus), I search for a dynamic way (something similar to “macro-expansion”).

Therefore I have tried to implement it with FindByName, but it seems as it don’t works or (more likely :smirk:) I understand it wrong.

In my code (checking values), I fill the name of the first element in a string-variable (cFocusElement).
Then, I want to set the focus to the first entry with missing data (before I scroll to the element).

Code:

if (!(cFocusElement == ""))
{
  EntryErfassung oReferenz = this.FindByName<EntryErfassung>(cFocusElement); 
  // Crash with "Could not resolve type: EntryErfassung"
  if (!(oReferenz == null))
    { oReferenz.SetFocus(); 
}

where EntryErfassung is the name of my custom-entry-class and cFocusElement contains the name of the created entry-object on the page. Further SetFocus() is a method in my class.

Error-message (at runtime) "Could not resolve type: EntryErfassung"
It also not works, if I add my namespace (MatrixGuide.EntryErfassung)

I then have done a test with a standard-label:

var lblx = this.FindByName<Label>("MailLabel"); 
// Crashes with “this element is not in a namescope”

where MailLabel is the name of a standard-label on the page.

I thought, that - with “FindByName” I could get a reference to an object of a page, but it seems, that I “thought wrong” :cry:

Can somebody give me a hint please..?

Thanks


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>