TypeConverter doesn't work in unity
Posted: 19 Apr 2019, 09:24
For every time I refer a ResourceDictionary in multiple places. Noesis will create multiple instance,although these ResourceDictionary are same. so I write a class inherit from ResourceDictionary named "SharableResdic",so that i can specify a TypeConverter to it
it worked in vs blend,but didn't work in unity
Code: Select all
[TypeConverter(typeof(SharableResdicConverter))]
public class SharableResdic : ResourceDictionary
{
public int RefNum { get; private set; }
internal SharableResdic Retain(){
RefNum++;
return this;
}
internal int Release(){
return --RefNum;
}
}
public class SharableResdicConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType){return sourceType == typeof(string);}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value is string){
return SharableResdicManager.Instance.Get(value as string);
} return null;
}
}
Code: Select all
<ex:SharableResdic>/Home/Views/LoginMain/LoginRes.xaml</ex:SharableResdic>