Variables for controls in code behind

Hi, I am new with Xamarin form, but I'm not with visual studio. I know that the xaml files have a code behind class, and I also know that when I add a control in the xaml file and add a x:Name propery, I should be able to access that control in code behind, but this is not happening in my visual studio for max.
If i add for example in my xaml something like

In the code behind class I should have a variable called myView of type Xamarin.Forms.Entry.
I can only get it by compiling /clean build several times, but this is really annoying. Have you exeperienced a similar behaviour ? If yes, how have you solved it?

Many thanks

Tagged:

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    > @simone.1127 said:
    > Hi, I am new with Xamarin form, but I'm not with visual studio. I know that the xaml files have a code behind class, and I also know that when I add a control in the xaml file and add a x:Name propery, I should be able to access that control in code behind, but this is not happening in my visual studio for max.
    > If i add for example in my xaml something like
    >
    >
    >
    > In the code behind class I should have a variable called myView of type Xamarin.Forms.Entry.
    > I can only get it by compiling /clean build several times, but this is really annoying. Have you exeperienced a similar behaviour ? If yes, how have you solved it?
    >
    > Many thanks

    I don’t n see your xaml code
  • simone.1127simone.1127 USMember

    Hi,
    I don't know why the code is missing, by the way it is a very simple piece of code:

    <Entry x:Name="myview"></Entry>

    typing it, it does not generate a variable called myview in code behind

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Article on posting your code so the site parser doesn't mangle/eat/loose it
    https://redpillxamarin.com/2016/12/13/faq-frequently-asked-questions/

    I should be able to access that control in code behind

    Just because you can' do a thing doesn't mean you should do a thing. 99% of the time accessing controls in code behind is wrong and a big red flag that your design is more like something form 1998 WinForms than modern 2017 architecture concepts.

    So before worrying about why you're having trouble reaching these controls let me ask why you think you need to and what you plan on doing with them once you fix the problem.

Sign In or Register to comment.