我一直在 WPF 中使用 Singleton 值转换器。但最近我和一位同事发生了争执,他说使用 valueconverters 的单例实例是不好的,因为它们只能由应用程序域卸载处理。他建议单例转换器仅在页面保持加载直到应用程序卸载的情况下才会派上用场。真的很想在这里了解WPF专家的意见。
编辑(举例):我有一个转换器
public class ABCConverter : IMultiValueConverter
{
private static ABCConverter _instance;
public static ABCConverter Instance
{
get { return _instance ?? (_instance = new ABCConverter()); }
}
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return true;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return false;
}
}
我目前在 xaml 中使用它作为
Converter="{x:Static conv:ABCConverter.Instance}"
提前致谢。
拉吉