Which code segment should you use?

You are developing a Silverlight 4 application. The application contains a Product class that has a publicBoolean property named IsAvailable.
You need to create a value converter that binds data to the Visibility property of a Button control. Which code segment should you use?

You are developing a Silverlight 4 application. The application contains a Product class that has a publicBoolean property named IsAvailable.
You need to create a value converter that binds data to the Visibility property of a Button control. Which code segment should you use?

A.
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization. CultureInfo
culture)
{
bool result = System.Convert.ToBoolean(parameter);
return result Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}}

B.
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization. CultureInfo
culture)
{
bool result = System.Convert.ToBoolean(value);
return result Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}}

C.
public class BoolToVisibilityConverter : PropertyPathConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization. CultureInfo
culture)
{
return this.ConvertTo(value, typeof(Visibility));
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}}

D.
public class BoolToVisibilityConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization. CultureInfo
culture)
{
bool result = System.Convert.ToBoolean(value);
return result Visibility. Visible : Visibility. Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}}



Leave a Reply 0

Your email address will not be published. Required fields are marked *