我使用.net标准创建了一个Xamarin表单应用程序。然后我在解决方案中添加了一个.net标准库项目,其中包括渲染,行为等常用代码。我通过右键单击依赖项和编辑引用菜单,将常见.net标准库项目的引用包含到主Xamarin表单项目中。最后,我尝试在主Xamarin表单的内容页面上包含渲染器文件的命名空间,方法是使用Xamarin.Forms指定下面的行;
namespace MyProject.Shared.Renderer
{
public class ExtendedEntry : Entry
{
public static readonly BindableProperty IsBorderErrorVisibleProperty = BindableProperty.Create(nameof(IsBorderErrorVisible), typeof(bool), typeof(ExtendedEntry),
false, BindingMode.TwoWay);
public bool IsBorderErrorVisible
{
get { return (bool)GetValue(IsBorderErrorVisibleProperty); }
set { SetValue(IsBorderErrorVisibleProperty, value); }
}
public static readonly BindableProperty BorderErrorColorProperty = BindableProperty.Create(nameof(BorderErrorColor), typeof(Color), typeof(ExtendedEntry),
null, BindingMode.TwoWay);
public Color BorderErrorColor
{
get { return (Color)GetValue(BorderErrorColorProperty); }
set { SetValue(BorderErrorColorProperty, value); }
}
public static readonly BindableProperty ErrorTextProperty = BindableProperty.Create(nameof(ErrorText), typeof(string), typeof(ExtendedEntry), string.Empty,
BindingMode.TwoWay);
public string ErrorText
{
get { return (string)GetValue(ErrorTextProperty); }
set { SetValue(ErrorTextProperty, value); }
}
}
}
xmlns:controls=“clr-namespace:MyProject.Shared.Renderer:assembly:MyProject.Shared”
Then I reference the control as
<controls:ExtendedEntry />
但这会产生构建错误,表示在程序集MyProject.Shared中找不到ExtendedEntry
请帮忙
实际上这个问题很常见,你的项目编译不正确或者在编译bin之后,obj都缺少这个类,这很好。
解:
如果您仍然面临此问题,请随时恢复。
祝好运
对不起......我犯了大错......一个真正的错误。
我在assembly属性中输入“:”而不是“=”。
它应该是xmlns:controls =“clr-namespace:MyProject.Shared.Renderer:assembly = MyProject.Shared”