Skip to main content
Home Forums Silverlight Programming Programming with .NET - General How to implement a simple type converter in Silverlight 2 Beta2
2 replies. Latest Post by AccidenceSilverlight on June 17, 2008.
(0)
Accidenc...
Member
1 points
4 Posts
06-13-2008 1:53 AM |
Hi,
I kown how to implement a simple type converter that provides a drop-down list of standard values in a property browser in WPF.
How do it in Silverlight 2 Beta2 ?
I use the namespace "System.ComponentModel" , but i can't find method "GetStandardValuesSupported","StandardValuesCollection" to override!
Yi-Lun L...
All-Star
25052 points
2,747 Posts
06-16-2008 4:17 AM |
Hello, TypeConverter.GetStandardValuesSupported is usually used in Windows Forms data binding. In WPF and Silverlight, you create a class implements IValueConverter. You need to check the type in the converter's methods. Here's a simple sample:
public class NameConverter : IValueConverter{public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){MyObject myObj = value as MyObject;if (myObj == null){throw new Exception("Invalid Type!");}return myObj.FirstName + " " + myObj.LastName;}public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){throw new NotImplementedException();}}
For StandardValuesCollection, I don't know what is it. Can you be more specific?
06-17-2008 9:17 PM |
Thank you!
Using "Compile Conditionally" this method my problem was resolved.