Re-Link Xaml and Code Behind in Visual Studio Solution

Viewed 1883

I have XAML file say SomePage.xaml.

I was making a mistake by refactored it's code behind class from SomePage to CardsPage class.

Now XAML file doesn't link with the code behind anymore.

Separate File

How to link these files together again?

3 Answers

If you are using Xamarin Forms, try editing your ".projitems" file located on the same directory of your .xaml files of your Xamarin project, there is the asociation between the .cs files and .xaml files like this

<Compile Include="$(MSBuildThisFileDirectory)MyPage.xaml.cs">
  <DependentUpon>MyPage.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>


<ItemGroup>
 <EmbeddedResource Include="$(MSBuildThisFileDirectory)MyPage.xaml">
  <SubType>Designer</SubType>
   <Generator>MSBuild:Compile</Generator>
 </EmbeddedResource>
</ItemGroup>

<Compile Update="C:\Projects\MyPage.xaml.cs">
  <DependentUpon>MyPage.xaml</DependentUpon>
</Compile>
Related