Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

No InitializeComponent or no reference to other projects

Hi everyone

I'm currently developing a mobile application using a Shared Project in Visual Studio 2015 with the Xamarin plug-in. The problem is that in the Code Behind of the XAML-pages the InitializeComponent isn't known; therefore the page doesn't know the views declared inside the XAML.

If I edit the XAML-page suddenly the InitializeComponent is known, but the references to my other projects are broken! So I can either choose between knowing and handling the views on page, or being able to access classes from other projects. But never both...

There are similar questions with the exact same problem for a while now, but none that supplies an answer! This greatly decreases productivity, plus I can't possibly imagine no one has come up with a solution or that Xamarin hasn't fixed this annoying bug!

Anyone that can help me out? Thanks in advance!

Best Answer

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    the InitializeComponent isn't known

    That's fairly common in a new project.

    Clean the solution then build each project one at a time from the top down: Shared, then android, then iOS etc.

    Then debug it to a device. Send it to your Android tablet or whatever one time.

    Close the solution and re-open it. This causes Visual Studio to go through its "Loading project" process on each project.

    Once you've gone through all this one time on a new project things should be fine.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    therefore the page doesn't know the views declared inside the XAML.

    Why would it need to? Code behind really shouldn't be aware of the GUI elements. A good rule of thumb is: If you're naming your GUI elements for anything other than being referenced in XAML by other GUI elements for binding, you're probably doing something wrong.

    For example: If you've binded the visibility of one element to another so they all show/hide together that would all be done in the XAML and not need any code behind, but would need the 'master' element to have a name. So that would be ok. If your C# is calling/affecting elements in the GUI by name that's a problem.

  • StefaanAvonds.3725StefaanAvonds.3725 USMember ✭✭✭

    That didn't work out, the problem is exactly the same...

    I sometimes use the view in my Code Behind for testing reasons - like if I'm playing around with them and want to know what their Properties are.

    Any other solutions or workarounds?

Sign In or Register to comment.