【问题标题】:Possible VS issue Type Local not found in current namespace可能的 VS 问题 Type Local not found in current namespace
【发布时间】:2019-09-19 14:56:33
【问题描述】:

构建失败,找不到在 xaml 中链接的 ImageCoverter,因此我可以提取绑定 {name} 并将其转换为 URL 以将图像拉入应用程序。

我已经添加了命名空间、资源字典、更改了命名空间、清理了构建、手动删除了 /bin /obj,一切。

好的,我有这个项目,GallogForms。该项目的内部是 GallogFroms、GallogForms.Android 和 GallogForms.ios。我在 GallogForms 之外也有名为 Gallog.Api 的 Api。所有这些都是在 GallogForms 根目录中完成的。我正在使用 NetStandarLibrary 2.0.3

ShipImageConverter.cs

namespace GallogForms.Images
{
    public class ShipImageConverter<T> : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return $"https://gallog.co/img/ships/{value}";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value.ToString().Replace("https://gallog.co/img/ships/", "");
        }
    }
}

xaml 标头

  mc:Ignorable="d"
             xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
             x:Class="GallogForms.Views.ShipsPage"
             xmlns:local="clr-namespace:GallogForms.Images;assembly=GallogForms"

xaml 资源字典

<ContentPage.Resources>
        <ResourceDictionary>
            <Color x:Key="Primary">#2196F3</Color>
            <Color x:Key="Accent">#96d1ff</Color>
            <Color x:Key="LightTextColor">#999999</Color>
            <local:ShipImageConverter x:Key="ShipImageConverter" />
        </ResourceDictionary>
    </ContentPage.Resources>

xaml 图像源

 <StackLayout Orientation="Vertical" Padding="8,0,8,0" BackgroundColor="#252629">
                            <Label Text="{Binding mfr}" FontFamily="zekton_regular.ttf#Zekton Rg" TextColor="White" FontSize="14" LineBreakMode="TailTruncation" />
                            <Label Text="{Binding name}" FontFamily="zekton_regular.ttf#Zekton Rg" TextColor="White" FontSize="14" LineBreakMode="TailTruncation" />
<Image Source="{Binding img, Converter={StaticResource ShipImageConverter}}" />
                        </StackLayout>

我尝试过使用程序集引用,没有它,将它放在 GallogFroms 的根目录中,将它放在 viewmodel 中,等等。

预期结果我读过很多人都遇到同样的问题,说命名空间重命名已经解决了这个问题。我的结果并不顺利。我希望它在 ShipPage.xaml 中构建链接 ShipImageConverter。

【问题讨论】:

  • 检查你的外壳! “本地”与“本地”不同
  • 好眼光,但不幸的是,我写了这篇文章。我复制粘贴的 github,我删除了代码以获得干净的构建并手动输入它。我得到的是智能文本自动填充参考字典中的 local:ShipImageSource 它已经硬编码到列表中。
  • 所以,我不能说我解决了这个问题。我仍然想了解它的根源,只是为了知道前进,但现在我更换了转换器,直接从我的 api json 填充的初始列表中提取文件名,我有一个字符串,在那里绑定 2 个字符串源,然后当 json 被打包到船舶主列表中时,图像名称将替换为图像的完整 url。非常有效,并且在异步方法中工作,它比我使用 {Binding img StringFormat='{gallog.co/img/ships{0:F0}'}" 对转换器进行硬编码时响应更快
  • @Dreamsforgotten 嗨,您是否参考this document 使用IValueConverter。如果解决了,你可以分享答案来标记它。
  • 据我所知,转换器类的公式是正确的,我没有在其中的任何方法上出错。我在编译时出错,因为文件完全丢失。

标签: c# android xaml xamarin.forms


【解决方案1】:

正如@JuniorJiang-MSFT 所指出的那样,当链接到 Xaml 时,我错过了转换器在其中包含 Type 参数的事实。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多