so you still Mode=TwoWay, so you append 1 type is: "UpdateSourceTrigger=Explicit" in Binding
For example:
Text="{Binding Path=NameHS,UpdateSourceTrigger=Explicit}"
After that you use UpdateSource And UpdateTarget via BindingExpression
BindingExpression be = textBox_Test.GetBindingExpression(TextBox.TextProperty);
//update source
be.UpdateSource() ;
//update target
be.UpdateTarget() ;
- UpdateSource and UpdateTarget for Children of FrameworkElement
public static partial class BindingHelper
{
public static void UpdateSource(this UIElement control , params Type_DependencyProperty[] list)
{
PrintLogicalTree(control , (be)=> be.UpdateSource() , list);
}
public static void UpdateTarget(this UIElement control, params Type_DependencyProperty[] list)
{
PrintLogicalTree(control, (be) => be.UpdateTarget() , list);
}
private static void PrintLogicalTree(object obj, Action
{
// Sometimes leaf nodes aren’t DependencyObjects (e.g. strings)
if (!(obj is DependencyObject)) return;
// Recursive call for each logical child
FrameworkElement element = obj as FrameworkElement;
if (element != null)
{
//Get dependency Property
DependencyProperty dp = FactoryDependencyPropertyCommon(element);
if (dp == null)
{
Type_DependencyProperty type_Dependency = list.FirstOrDefault(tdp => tdp.Type == element.GetType());
if (type_Dependency != null)
dp = type_Dependency.DependencyProperty;
}
if (dp != null)
{
BindingExpression be = element.GetBindingExpression(dp);
if (be != null && action != null)
{
action(be);
}
//be.UpdateSource();
}
}
foreach (object child in LogicalTreeHelper.GetChildren(obj as DependencyObject))
PrintLogicalTree(child, action, list);
}
private static DependencyProperty FactoryDependencyPropertyCommon(FrameworkElement element)
{
//if (element.GetType() == typeof(TextBox))
// return TextBox.TextProperty;
//else if (element.GetType() == typeof(CheckBox))
// return CheckBox.IsCheckedProperty;
return null;
}
}
public class Type_DependencyProperty
{
public Type Type { get; set; }
public DependencyProperty DependencyProperty { get; set; }
}
No comments:
Post a Comment