【发布时间】:2013-07-01 23:09:23
【问题描述】:
我有一个带有 INotifyPropertyChanged 接口的绑定列表。一切正常。 此绑定列表是绑定到列表框的文件名列表。我只想要显示的名称,而不是整个路径,但是当我选择一个文件名并加载文件时,我需要整个路径。
我为此目的使用 IValueConverter,其中使用 Path.GetFileName 属性来更改文件名的完整路径。绑定是正确的,但我的绑定列表并没有按照我的意愿更改值。我在下面粘贴 IValueConverter 代码。请让我知道这段代码有什么问题。我提到了转换here。
[ValueConversion(typeof(string), typeof(string))]
public class pathtoname : IValueConverter
{
public object Convert(object value, Type targetType, object parameter ,CultureInfo culture)
{
BindingList<string> ls = value as BindingList<string>;
ls.Select(x => "WW");
return ls;//all values should be WW. But they are not.(debugger)
}
public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture)
{
return null;
}
}
编辑:值现在被转换。但是现在如何找回整个路径呢?我要保留 2 个清单吗?一种用于完整路径,另一种名称类似于here。有更好的解决方案吗?
【问题讨论】:
标签: c# wpf list mvvm ivalueconverter