use*_*962 64 xamarin xamarin.forms
我正在使用Visual Studio来试用Xamarin.Forms.我正在尝试遵循指南:http: //developer.xamarin.com/guides/cross-platform/xamarin-forms/xaml-for-xamarin-forms/getting_started_with_xaml/
简而言之,我使用PCL创建了一个Xamarin.Forms解决方案,然后尝试将其添加Forms XAML Page到PCL项目中.
创建的代码隐藏看起来像这样:
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
}
}
Run Code Online (Sandbox Code Playgroud)
这里的问题InitializeComponent();是红色.当我尝试建立时,我得到了通知The name 'InitializeComponent' does not exist in the current context
我一直在寻找解决方案,即使其他人遇到同样的麻烦,他们的解决方案也不适合我.以下是我尝试使用的一条建议:http: //blog.falafel.com/xamarin-error-initializecomponent-does-not-exist-in-the-current-context/
如果您有解决此问题的方法,请告诉我.谢谢!
更新:
我的PCL(我也想添加我的XAML页面)包含:
App.cs:
public class App : Application
{
public App()
{
// The root page of your application
MainPage = new ContentPage
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Welcome to Xamarin Forms!"
}
}
}
};
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
Run Code Online (Sandbox Code Playgroud)
和我的XAML页面:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamaTest.MyXamlPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
代码隐藏:
public partial class MyXamlPage : ContentPage
{
public MyXamlPage()
{
InitializeComponent();
}
}
Run Code Online (Sandbox Code Playgroud)
Dus*_*gal 56
更新: 这个错误通常不会出现在VS 2015中,如果有的话,这是我原来的答案:
找到了解决方案!右键单击.XAML文件,选择" 属性".
您将看到一个名为Custom Tool的属性.将其值更改MSBuild:Compile为MSBuild:UpdateDesignTimeXaml
这将解决问题.不知道downvote,但这是我的截图:
它很少再出现.如果是这样,只需打开Xaml和代码隐藏文件并保存它们.我知道,它不是最好的解决方案,但它完成了工作.
roo*_*oot 34
我有时会得到这个,这是迄今为止解决它们的清单:
确保.xaml和.xaml.cs中的命名空间匹配
从正确的父级继承 - 页面的ContentPage和控件的ContentView
Embedded Resource在共享项目中将.xaml文件的构建操作设置为if.
小智 12
我遇到了这个问题.它与VS中的XAML文件编码相关联.我正在使用VS2015.
我解决了这个问题如下:
打开项目中的*.xaml文件,然后单击"保存"按钮.(将在VS2015中应用正确的编码).
然后重新打开项目并重建它.现在没有错误.
Tho*_*ler 10
更新Xamarin.Forms NuGet包应该可以完成这项工作
这可能不是您的情况,但我遇到了类似的问题,我的问题是xaml和名称不匹配的代码。例如,根据您的示例,如果名称空间后面的代码是XamaTest(大多数情况下为应用程序的名称),并且类名为MyXamlPage,则您的xaml类名称必须为XamaTest.MyXamlPage([namespace]。[[classname])
在创建一个空的xaml和后面的代码后,我很傻,我在xaml中更改了类的名称,并且遇到了这个错误。
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamaTest.MyXamlPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
后台代码:
public partial class MyXamlPage : ContentPage
Run Code Online (Sandbox Code Playgroud)
尝试在 xaml 页面上添加 ax:Name="..." ...有时仍然得到它)。我使用 Xamarin.Forms 的最新版本 (1.5.0.6447)...
XAML 不适用于共享项目 - 它仅适用于可移植项目...
| 归档时间: |
|
| 查看次数: |
45156 次 |
| 最近记录: |