How can I connect xaml and xaml.cs files

前端 未结 11 1898
既然无缘
既然无缘 2020-12-14 05:27

I had a VB projected and converted it to C# using online conversion tools. Now the problem is xaml and xaml.cs file do not connect to each other, t

相关标签:
11条回答
  • 2020-12-14 05:55

    Using Xamarin Shared Code solution:

    1) Go to you project folder after unloading the shared project

    2) Find the projitems file and edit that adding the DependentUpon tag as described in other answers above.

    3) Save the file

    4) Go back to visual studio and you should get a dialog that allows you to reload all or just open the project again.

    0 讨论(0)
  • 2020-12-14 05:58

    If you cannot get the IDE to do it (Papa John's post), then you can do it by editing the project file.

    That information is in the .csproj file (which is an XML file -- you can open it in a text editor, or by right-clicking on it, choosing "unload", and then opening it -- choose reload to load it up as a project again).

    Here is the information to look for, you would need to add the "DependentUpon" tag.

    <Compile Include="TheFile.xaml.cs">
      <DependentUpon>TheFile.xaml</DependentUpon>
    </Compile>
    
    0 讨论(0)
  • 2020-12-14 06:00

    This is simple, try to add in project existing items and select the XAML (not .cs, etc.) files in list of formats. In VS2010 thats helps.

    0 讨论(0)
  • 2020-12-14 06:00

    I was able to just restart Visual Studio for Mac 2019 v16.2 and it reconnected my .xaml & .cs files that should've been connected.

    If that doesn't work, Hitsa's solution worked for me as well on a separate occasion.

    0 讨论(0)
  • 2020-12-14 06:00

    The usual - Close Visual Studio, delete the vs folder in the root folder of your solution and reopen Visual Studio (2019) just worked for me.

    0 讨论(0)
  • 2020-12-14 06:01

    An even easier and faster solution for Xamarin Forms projects, no need to touch csproj file at all, very quick fix.

    Make sure you have Show All Files selected for solution explorer - it may be on by default.

    1. Select all affected files
    2. Right click > Exclude from Project
    3. Select the same files again (should be faded out)
    4. Right Click > Include in Project

    They should now all be nested correctly and all the changes necessary to the .csproj file will be done.

    You may have an InitializeComponent() does not exist in the current context) error after this. If that's the case, the simple fix is..

    • Select all affected items and change Build Action from Page to Embedded Resource
    0 讨论(0)
提交回复
热议问题