I want binding content in Checkbox to ColorConvert by example I want fill a string like "Red" in ColorConvert but I don't know how to do that.
<CheckBox IsChecked="{Binding Path=ColorConvert}" Content="Red"/>
namespace ChatTest_MVVM { public class ColorConverter : IValueConverter { public object Convert(object o, Type type, object parameter, CultureInfo culture) { string color = (string)o; if (type.Name == "Brush") { if (color == "Red") { return Brushes.Red; } else if(color == "Blue") { return Brushes.Blue; } } return Brushes.Yellow; ; } public object ConvertBack(object o, Type type, object parameter, CultureInfo culture) { return null; } } public class MyData : INotifyPropertyChanged { private string colorConvert;
public MyData()
{
colorConvert = "Red";
textConvert = true;
}
public string ColorConvert
{
get { return colorConvert; }
set
{
colorConvert = value;
OnPropertyChanged("ColorConvert");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire