Binding 在silverlight复选框中的事件处理程序之后调用绑定
我在silverlight中有一个复选框,我将checkbox IsChecked属性与一个字符串属性绑定在一起,该字符串属性存储像“True”和“False”这样的值。我在绑定中使用了一个转换器将字符串值转换为bool。我还有复选框“checked”和“unchecked”事件的事件处理程序 当我选中或取消选中复选框时,会调用绑定更新以及复选框“已选中”和“未选中”事件的处理程序,但会先调用hanlder,然后再调用绑定更新。但是我需要先使用复选框更新绑定(对于IsChecked属性),然后再使用事件handler进行调用。我怎样才能做到这一点 //与我绑定的属性IsChecked属性为“PropertyPath”Binding 在silverlight复选框中的事件处理程序之后调用绑定,binding,silverlight-4.0,Binding,Silverlight 4.0,我在silverlight中有一个复选框,我将checkbox IsChecked属性与一个字符串属性绑定在一起,该字符串属性存储像“True”和“False”这样的值。我在绑定中使用了一个转换器将字符串值转换为bool。我还有复选框“checked”和“unchecked”事件的事件处理程序 当我选中或取消选中复选框时,会调用绑定更新以及复选框“已选中”和“未选中”事件的处理程序,但会先调用hanlder,然后再调用绑定更新。但是我需要先使用复选框更新绑定(对于IsChecked属性),然后再
// binding code
CheckBox checkBoxControl = new CheckBox();
Binding binding = new Binding();
binding.FallbackValue = false;
binding.Mode = BindingMode.TwoWay;
binding.Source = this;
binding.Converter = new BoolStringToBoolConverter();
binding.Path = new PropertyPath("PropertyPath");
checkBoxControl.SetBinding(GenericCheckBox.IsCheckedProperty, binding);
checkBoxControl.Checked += new RoutedEventHandler(checkBox_CheckedProperty_Changed);
handler
void checkBox_CheckedProperty_Changed(object sender, RoutedEventArgs e)
{
CheckBox chkBox = sender as CheckBox;
// Here the value of 'PropertyPath' is not updated as binding is not updated yet
}
下面是我在绑定中使用的转换器
public class BoolStringToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value.ToString().ToUpper().Trim().Equals("TRUE"))
{
return true;
}
else
{
return false;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value.GetType().Equals(typeof(bool)) && (bool)value)
{
return "True";
}
else
{
return "False" ;
}
}
}
单击复选框时,首先调用事件处理程序,然后调用转换器的“ConvertBack”方法,因此在事件处理程序中,我没有得到属性“PropertyPath”的更新值
如何确保在调用复选框事件处理程序之前调用绑定更新