[英]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.