【问题标题】:Xamarin forms cannot access controls by it "x:Name"Xamarin 表单无法通过它“x:Name”访问控件
【发布时间】:2018-08-19 03:08:12
【问题描述】:

今天我遇到了一些问题。请帮帮我。

我在 IOS 和 Android 上创建了一个跨平台应用程序。所以我试图访问我的 MainPage 控件表单 .cs 文件,但我不能。这是提供的代码。

MainPage.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"
             xmlns:local="clr-namespace:Movies"
             x:Class="Movies.MainPage">


    <TableView x:Name="mainTable">
        <TableSection>
            <ViewCell>
                <ViewCell.View>
                    <Label Text="Hello"></Label>
                </ViewCell.View>
            </ViewCell>
        </TableSection>
    </TableView>

</ContentPage>

MainPage.xaml.cs

using Xamarin.Forms;
namespace Movies
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            mainTable.
        }
    }
}

https://i.imgur.com/OKO3yYc.png

项目运行成功。

https://i.imgur.com/ondjVkP.png

我尝试在 VS 安装程序中重建甚至恢复 VS17。 this.mainTable 也不起作用。

【问题讨论】:

  • this.mainTable 有效吗?
  • 不,不是。我尝试在 VS 安装程序中重建甚至恢复 VS17
  • 但是代码可以编译吗?如果你写 Console.WriteLine(mainTable.ToString());它会编译并写一些东西吗?
  • 用 Console.WriteLine(mainTable.ToString()); 编译。奇怪的。输出“Xamarin.Forms.TableView”
  • 它正在编译,我可以使用这个控件,谢谢,但是对于我作为 Xamarin 表单开发的初学者来说,没有 IntelliSense 真的很难做到。有人可以帮忙吗?

标签: xamarin xamarin.forms


【解决方案1】:

点击 .XAML 文件,选择属性。

查看名为自定义工具的属性。将其值从 MSBuild:Compile 更改为 MSBuild:UpdateDesignTimeXaml,或者如果它为空白,则将其设置为 MSBuild:UpdateDesignTimeXaml。

这将解决问题。

【讨论】:

    【解决方案2】:

    构建项目一次,即可访问.cs文件中的名称。

    【讨论】:

      猜你喜欢
      • 2014-03-03
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多