I have multiple user controls in XAML with shared code that I want to put in a base page so I want
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
}
}
basepage.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()
{
}
}
}
The system wont compile and i get the following error
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
This seems like a simple thing to do but is causing a headache, any ideas ?
Should be:
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
}
Also you do not need to explicitly declare the name space as both SingleLine and BaseUserControl are in the same namespace....
public partical class SingleLine : BaseUserControl
This should work....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.