【发布时间】:2016-12-27 03:23:52
【问题描述】:
我有一个 Xamarin Forms 组件,它在 Xaml 中有一个 StackLayout。我给了它一个 stackView 的 xName。
我有另一个自定义组件,我想从后面的代码中以编程方式添加到堆栈布局中,但我遇到了错误,我不知道为什么。
我收到的错误是我的自定义登录视图无法转换为 Xamarin.Forms.View
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace TechPact
{
public partial class CustomView : ContentPage
{
public CustomView()
{
InitializeComponent();
stackView.Children.Add(new CustomLoginView());
}
}
}
这是我的登录视图
?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="TechPact.CustomLoginView">
<StackLayout>
<Button Text="Login with Facebook" />
</StackLayout>
</ContentPage>
这是登录视图的代码
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace TechPact
{
public partial class CustomLoginView : ContentPage
{
public TechPactLoginView()
{
InitializeComponent();
}
}
}
【问题讨论】: