【发布时间】: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