【问题标题】:ByteToStringConverter does not implement interface member ...IValueConverter.ConvertBack(...)'?ByteToStringConverter 没有实现接口成员...IValueConverter.ConvertBack(...)'?
【发布时间】:2015-06-01 19:09:29
【问题描述】:

我的 ByteToStringConverter,它完成了将字节转换为人类可读大小(MB、GB 等)的工作

错误 1 ​​名称“ByteToStringConverter”在命名空间“clr-namespace:zemanFileManager.Konverteri”中不存在。 C:\Users\Nikola\Documents\Visual Studio 2013\Projects\zemanFileManager\zemanFileManager\zemanFileManager.xaml 14 9 zemanFileManager

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace zemanFileManager.Konverteri
{
    public class ByteToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            string size = "0 KB";

            if (value != null)
            {

                double byteCount = 0;

                byteCount = System.Convert.ToDouble(value);

                if (byteCount >= 1073741824)
                    size = String.Format("{0:##.##}", byteCount / 1073741824) + " GB";
                else if (byteCount >= 1048576)
                    size = String.Format("{0:##.##}", byteCount / 1048576) + " MB";
                else if (byteCount >= 1024)
                    size = String.Format("{0:##.##}", byteCount / 1024) + " KB";
                else if (byteCount > 0 && byteCount < 1024)
                    size = "1 KB";    //Bytes are unimportant ;)            
            }

            return size;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }

xaml 代码,在这里我还知道命名空间中不存在 ByteToStringConverter,尽管它确实存在。我正在使用另一个名为 HeaderToImageConverter 的转换器,它工作得很好......

Controls:MetroWindow x:Class="zemanFileManager.ZemanFileManager"

xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
GlowBrush="{DynamicResource AccentColorBrush}"
WindowStartupLocation="CenterScreen"
WindowState="Maximized"
Title="ZemanFileManager" Height="700" Width="870" MinHeight="500" MinWidth="870" Icon="Slike/floppySlika.png"
xmlns:local="clr-namespace:zemanFileManager"            
              >

<Window.Resources>
    <local:ByteToStringConverter x:Key="BytesToString" />
</Window.Resources>

    <ListView.View>
        <GridView>
            <GridViewColumn Width="220" Header="Ime" DisplayMemberBinding="{Binding Name}" />
            <GridViewColumn Width="150" Header="Vrijeme kreiranja" DisplayMemberBinding="{Binding CreationTime}" />
            <GridViewColumn Width="100" Header="Veličina" DisplayMemberBinding="{Binding XPath=Length, Converter={StaticResource BytesToString}}" />
            <GridViewColumn Width="100" Header="Ekstenzija"  DisplayMemberBinding="{Binding  Extension}" />

        </GridView>
    </ListView.View>
</ListView>

【问题讨论】:

    标签: c# wpf xaml converter ivalueconverter


    【解决方案1】:

    您的 XML 命名空间声明 local 引用了命名空间 zemanFileManager,但转换器位于命名空间 zemanFileManager.Konverteri

    添加另一个命名空间声明:

    xmlns:converter="clr-namespace:zemanFileManager.Konverteri"
    ...
    <converter:ByteToStringConverter x:Key="BytesToString" />
    

    【讨论】:

    • 感谢您的宝贵时间。不幸的是,我仍然收到错误 -> link to error pic
    • 请在您的问题中添加对该错误的描述。
    猜你喜欢
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多