Looking to figure this one out. Have a bit field in our table which is bound to a combobox. I would like teh combo to display a "Yes" or "No" as related to 0 for No and 1 for Yes.
Figured this would be easy but ??
Tried writting a YesNo converter but its giving errors and not displaying anything in teh dropdown. I have the converter in a resource in another file so yes thats the correct spelling on the xaml code for it.
Figured this would be easy but ??
Tried writting a YesNo converter but its giving errors and not displaying anything in teh dropdown. I have the converter in a resource in another file so yes thats the correct spelling on the xaml code for it.
Code:
public class BooleanToYesNoConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Debugger.Break();
if (value is bool)
{
if ((bool)value == true)
return "Yes";
else
return "No";
}
return "No";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Debugger.Break();
switch (value.ToString().ToLower())
{
case "yes":
return true;
case "no":
return false;
}
return false;
}
}
Code:
<ComboBox Margin="24,3,0,3" Width="162" HorizontalAlignment="left" telerik:StyleManager.Theme="Office_Blue"
ItemsSource="{Binding Path=Licensed}"
SelectedValue="{Binding Path=CurrentEntity.Licensed, Mode=TwoWay, Converter={StaticResource BooleanToYesNoConverter1}, diag:PresentationTraceSources.TraceLevel=High}" />
Code:
//Loading procedure...
Licensed = new BindableCollection<int>();
Licensed.AddRange(new List<int>() { 0, 1});
//Property being bound to
private BindableCollection<int> _licensed;
public BindableCollection<int> Licensed
{
get { return _licensed; }
set { SetValueAndNotify(() => Licensed, ref _licensed, value); }
}