![](/img/trans.png)
[英]How to create custom URL based xaml namespace (xmlns) in Xamarin Forms?
[英]Cannot create xmlns for Xamarin.Forms project namespace
尝试为当前项目创建新的XAML命名空间时遇到以下编译错误
Error: Failed to resolve assembly: 'TodoQ.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
我一直在使用自己和外部项目中的自定义控件,并且编译器从未抱怨过任何一个。 这是XAML(省略号是我决定省略的其他一些标准名称空间):
<ContentPage xmlns:util="clr-namespace:TodoQ.Utilities"
xmlns:custom="clr-namespace:TodoQ.Controls"
xmlns:swipecards="clr-namespace:SwipeCards.Controls;assembly=SwipeCards.Controls"
... x:Class="TodoQ.Views.ItemsPage" Title="{Binding Title}" x:Name="BrowseItemsPage">
如您所见,我有两个名称空间引用了我当前的Xamarin.Forms项目。 custom
名称空间有效,但是如果我尝试使用util
,则会收到上述错误。 另一方面, swipecards
名称空间可以完美运行。
我尝试指定程序集,例如xmlns:util="clr-namespace:TodoQ.Utilities;assembly=TodoQ"
,但似乎没有什么不同。
到目前为止,我唯一使用util
就是尝试添加一个转换器:
<Grid.Resources>
<util:IsZero x:Key="IsZero" />
</Grid.Resources>
有人知道我在做什么错吗? 我几乎在这里扯头发。 使用WPF版本的XAML,事情要简单得多,这一切似乎都可以在那儿工作。
编辑:这是根据要求的实用程序文件:
using System;
using System.Globalization;
using Xamarin.Forms;
namespace TodoQ.Utilities
{
public class IsZero : IValueConverter
{
public object Convert(object value,
Type targetType,
object parameter,
CultureInfo language)
{
return ((int)value) == 0;
}
public object ConvertBack(object value,
Type targetType,
object parameter,
CultureInfo language)
{
throw new NotImplementedException();
}
}
}
老实说,我认为还有别的东西,这可能是您尝试使用它的方式,您的代码是正确的:
ItemsPage :
<?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:util="clr-namespace:TodoQ.Converters;assembly=TodoQ"
x:Class="TodoQ.Views.ItemsPage">
<StackLayout.Resources>
<ResourceDictionary>
<util:IsZero x:Key="IsZero" />
</ResourceDictionary>
</StackLayout.Resources>
<ContentPage.Content>
<StackLayout>
<Grid HorizontalOptions="CenterAndExpand" >
<Label Text="Hello World" Grid.Row="{Binding UserL , Converter={StaticResource IsZero}}" Grid.Column="0" />
</Grid>
</StackLayout>
</ContentPage.Content>
</ContentPage>
我解决了这个问题。 愚蠢的错误。 典型。
我缺少<ResourceDictionary>
标记,并且在转换器定义中也使用x:Name
而不是x:Key
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.