Exemple #1
0
        //Compares the current value of the text box and the properties of the source that is bound,
        //return true if modified, false otherwise
        public static bool IsChanged(TextBox sender)
        {
            DependencyObject   element = null;
            DependencyProperty dp      = null;

            GetTargetElement(sender, out element, out dp);
            if (element == null || dp == null)
            {
                return(false);
            }
            BindingExpression bindingExpression = BindingOperations.GetBindingExpression(element, dp);
            //using the current BindingExpression, get the string when of the target text property was set to the value of the source
            //Otherwise, when StringFormat or converter is set or the type of the property is not a string
            //problem happens how to convert it
            string propertyValue = PropertyPathHelper.GetTargetValue(bindingExpression);
            string elementValue  = element.GetValue(dp) as string;

            return(!IsSame(propertyValue, elementValue));
        }
Exemple #2
0
        public static bool UpdateSource(TextBox sender)
        {
            DependencyObject   element = null;
            DependencyProperty dp      = null;

            GetTargetElement(sender, out element, out dp);
            if (element == null || dp == null)
            {
                return(true);
            }
            BindingExpression bindingExpression = BindingOperations.GetBindingExpression(element, dp);

            if (bindingExpression == null)
            {
                return(true);
            }
            string elementValue = element.GetValue(dp) as string;

            bindingExpression.UpdateSource();
            string propertyValue = PropertyPathHelper.GetTargetValue(bindingExpression);

            return(IsSame(elementValue, propertyValue));
        }