为什么WPF/XAML添加了3“;嘲弄;对象到我的ViewModel中的IEnumerable集合?
我在ViewModel中定义了如下属性:为什么WPF/XAML添加了3“;嘲弄;对象到我的ViewModel中的IEnumerable集合?,wpf,xaml,design-time,Wpf,Xaml,Design Time,我在ViewModel中定义了如下属性: public IEnumerable<SubsystemFilterState> CurrentFilterStates { get; private set; } 转换器: public class FilterIndicatorConverter : IValueConverter { public object Convert(object value, Type targetType, object paramet
public IEnumerable<SubsystemFilterState> CurrentFilterStates { get; private set; }
转换器:
public class FilterIndicatorConverter
: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var indicator = "No Filter Selected";
if (value != null)
{
IEnumerable<SubsystemFilterState> states = (IEnumerable<SubsystemFilterState>)value;
indicator = states.Count() > 1
?
"Multiple Systems"
:
states.First().Acronym.ToString();
}
return indicator;
}
catch (Exception ex)
{
return ex.Message;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
其中显示以下内容:
看起来VisualStudio在设计时添加了这些,但为什么它与我的属性类型不匹配?我能关掉这个吗?什么是
DesignTools
名称空间?您最初是在VS中构建这个XAML还是使用Blend?根据我的经验,Blend可以添加这些东西。因此,我放弃了使用它。在window/usercontrol(XAML的根)中是否有任何设计名称空间或属性?没有,这都是用Visual Studio构建的。现在,我的XAML中确实有名称空间的东西,其中之一是混合名称空间,但它是在创建新项目时自动添加的,所以我把它放在那里了。我是WPF新手,所以我不知道名称空间(如果有的话)会对这一点产生什么影响。那么,在设计期间,您希望CurrentFilterStates
的计算结果是什么?如何说明您对ViewModel的看法?VS WPF设计器在设计期间没有执行您的所有代码,因此,如果它包装了我的一些类型而无法执行任何操作,我不会太担心。@MarkusHütter我想我希望它的计算结果与属性的类型相同。我正在使用Prism和AutoWireViewModel
。我可以用它包装我的类型,但是转换器的目的不是让复杂的类型可以显示吗?最后,我输入了一些代码,专门检查转换器永远不会接收到的值。我不介意只做一次,但是对于每个要解释的转换器(IMO),Blend/VS中的一个bug会不必要地膨胀我的代码。
public class FilterIndicatorConverter
: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var indicator = "No Filter Selected";
if (value != null)
{
IEnumerable<SubsystemFilterState> states = (IEnumerable<SubsystemFilterState>)value;
indicator = states.Count() > 1
?
"Multiple Systems"
:
states.First().Acronym.ToString();
}
return indicator;
}
catch (Exception ex)
{
return ex.Message;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
public class FilterIndicatorConverter
: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var indicator = "";
if (value != null)
{
foreach (dynamic test in value as IEnumerable)
{
Type type = test.GetType();
indicator += string.Format("Start{0}" +
"AssemblyQualifiedName: {0}{6}{1}{0}" +
"Namespace: {0}{6}{2}{0}" +
"Assembly: {0}{6}{3}{0}" +
"BaseType: {0}{6}{4}{0}" +
"FullName: {0}{6}{5}{0}{0}",
"\n",
type.AssemblyQualifiedName,
type.Namespace,
type.Assembly,
type.BaseType,
type.FullName,
" ");
}
}
return indicator;
}
catch (Exception ex)
{
return ex.Message;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}