C#/XAML Compile Error - Various Errors (The name “

2019-04-06 14:14发布

问题:

EDIT:

Here are the pastebins for the code:

BasicPage1.xaml.cs

BasicPage1.xaml

LayoutAwarePage.cs

EDIT 2

I have added a MS Connect ticket here:

https://connect.microsoft.com/VisualStudio/feedback/details/771648/c-xaml-compile-error-various-errors-the-name-layoutawarepage-does-not-exist#tabs

Right a head scratcher which I'm hoping others have experienced and know how to resolved as I'm a little disheartened by the whole affair.

The Problem

I have been working on a Windows Store App using C#/XAML to learn the ropes. After hours spent learning I decided to start my own App, which is fine. The issue is, after adding a few Views etc, I started getting the following error within my XAML files (All of them):

Error 5 The name "LayoutAwarePage" does not exist in the namespace "using:Accountable.Common". G:\Coding Projects\Visual Studio 2012\SAVED\Accountable\Accountable\BasicPage1.xaml 1 1 Accountable

Which is strange because the Accountable.Common is declared within the XAML file:

<common:LayoutAwarePage
x:Name="pageRoot"
x:Class="Accountable.BasicPage1"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Accountable"
xmlns:common="using:Accountable.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

So i read here that closing the XAML files down and closing Visual Studio 2012 and re-opening, plus Building, resolves this issue. It didnt. It now causes the following errors within the Common files created when you first create new templates:

Error 1 'Accountable.Common.BooleanNegationConverter' does not implement interface member 'Windows.UI.Xaml.Data.IValueConverter.ConvertBack(object, System.Type, object, string)' G:\Coding Projects\Visual Studio 2012\SAVED\Accountable\Accountable\Common\BooleanNegationConverter.cs 9 25 Accountable

Error 2 'Accountable.Common.BooleanNegationConverter' does not implement interface member 'Windows.UI.Xaml.Data.IValueConverter.Convert(object, System.Type, object, string)' G:\Coding Projects\Visual Studio 2012\SAVED\Accountable\Accountable\Common\BooleanNegationConverter.cs 9 25 Accountable

Error 3 'Accountable.Common.BooleanToVisibilityConverter' does not implement interface member 'Windows.UI.Xaml.Data.IValueConverter.ConvertBack(object, System.Type, object, string)' G:\Coding Projects\Visual Studio 2012\SAVED\Accountable\Accountable\Common\BooleanToVisibilityConverter.cs 20 25 Accountable

Error 4 'Accountable.Common.BooleanToVisibilityConverter' does not implement interface member 'Windows.UI.Xaml.Data.IValueConverter.Convert(object, System.Type, object, string)' G:\Coding Projects\Visual Studio 2012\SAVED\Accountable\Accountable\Common\BooleanToVisibilityConverter.cs 20 25 Accountable

I haven't changed BooleanNegationConverter.cs or BooleanToVisibility.cs. What have i done to try and resolved the issue:

  1. Investigated other SO Posts, to no avail
  2. Deleted the Solution SUO File with no luck
  3. Removed my XAML Files, Classes (Models and ViewModels) and deleted Common Classes and created a new Basic Page. This causes the Project to load the classes again. The same problem.
  4. Removed the reference to Syncfusion Controls for WinRT XAML which i used for custom DatePicker controls. Still the same issue.
  5. Repaired Visual Studio 2012 - Nothing happened still the same problems.

I'm completely at a loss. I have created a new Project and the problem doesn't exist. I dont really want to start my Project again!

FYI - LayoutPageAware.cs is included in the Project:

回答1:

I believe that the LayoutAwarePage is defined in the Common folder, and is automatically generated the first time you create a Basic Page

  • Right Click on your prject
  • Click Add
  • Click "New Item"
  • click "Basic Page"
  • click add.

You might get a dialog saying

"This addition depends on files that are missing from your project. Without these files you must resolve dependencies on the Common namespace manually. Add the missing files automatically?"

click yes

and then try building again