XAML Xamarin 窗体中的基页
本文关键字:基页 窗体 Xamarin XAML | 更新日期: 2023-09-27 17:56:14
>我在 XAML 中有多个用户控件,其中包含共享代码,我想将其放在基本页面中,所以我想要
singleLine.xaml --> singleLine.xaml.cs --- > basepage.cs
doubleLine.xaml --> doubleLine.xaml.cs --- > basepage.cs
singleLine.xaml
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" Margin="0" BackgroundColor="White">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped"/>
</StackLayout.GestureRecognizers>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" Margin="0" BackgroundColor="White">
<Label x:Name="ViewTitle" Style="{StaticResource lblJobDetailName}" />
<Label x:Name="ViewValue" Style="{StaticResource lblJobDetailValue}" />
</StackLayout>
<Image x:Name="EditIcon" Source="edit.png" Margin="15,15,15,15" IsVisible="false" WidthRequest="15" HeightRequest="15" />
</StackLayout>
singleLine.xaml.cs
using System;
using Xamarin.Forms;
namespace Client.UI.Pages.UserControls
{
public partial class SingleLine : Client.UI.Pages.UserControls.BaseUserControl
{
// do stuff
#region Constructors
public SingleLine()
{
InitializeComponent();
}
#endregion
}
}
基页.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Client.UI.Pages.UserControls
{
public class BaseUserControl: Xamarin.Forms.ContentView
{
public BaseUserControl()
{
}
}
}
系统无法编译,我收到以下错误
Error CS0234 The type or namespace name 'BaseUserControl' does not exist in the namespace 'Client.UI.Pages.UserControls' (are you missing an assembly reference?) Client.UI C:'Projects'Client.UI'Pages'UserControls'SingleLineItem.xaml.cs 8 Active
这似乎是一件简单的事情,但令人头疼,有什么想法吗?
应该是:
using System;
using Xamarin.Forms;
namespace Client.UI.Pages.UserControls
{
public partial class SingleLine : Client.UI.Pages.UserControls.BaseUserControl
{
// do stuff
#region Constructors
public SingleLine()
{
InitializeComponent();
}
#endregion
.... etc
} // end of class
}
此外,您不需要显式声明命名空间,因为 SingleLine 和 BaseUserControl 位于同一命名空间中。
public partical class SingleLine : BaseUserControl
这应该有效....