Hello,
i have an Attached Property with a list of a custom class. A Property of the custom class is bound to a textbox text.
I want to get an update or any function called when i enter text in the textbox or the bound value is changing.
It looks to me that the binding is lost.
Do you have any suggestions?
CustomClass:
public class ComparsionCondition : DependencyObject { public static readonly DependencyProperty BindingValueProperty = DependencyProperty.Register("BindingValue", typeof(string), typeof(ComparsionCondition), new PropertyMetadata("bindval")); public string BindingValue { get { return (string)GetValue(BindingValueProperty); } set { SetValue(BindingValueProperty, value); } } }
Behavior:
public static class ComparsionBehavior { #region ComparsionConditions public static TrulyObservableCollection<ComparsionCondition> GetComparsionConditions(DependencyObject frameworkElement) { return (TrulyObservableCollection<ComparsionCondition>)frameworkElement.GetValue(ComparsionConditionsProperty); } public static void SetComparsionConditions(DependencyObject frameworkElement, TrulyObservableCollection<ComparsionCondition> value) { frameworkElement.SetValue(ComparsionConditionsProperty, value); } public static readonly DependencyProperty ComparsionConditionsProperty = DependencyProperty.RegisterAttached( "ComparsionConditions", typeof(TrulyObservableCollection<ComparsionCondition>), typeof(ComparsionBehavior), new UIPropertyMetadata(new TrulyObservableCollection<ComparsionCondition>(), OnComparsionConditionsChanged)); static void OnComparsionConditionsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { HandlePropertyChanged(sender); } #endregion }
XAML usage:
<TextBox Text="85" x:Name="tb_value"></TextBox><Border><Behavior:ComparsionBehavior.ComparsionConditions><Behavior:ComparsionCondition BindingValue="{Binding Path=Text, ElementName=tb_value}"></Behavior:ComparsionCondition></Behavior:ComparsionBehavior.ComparsionConditions></Border>
Best regards,
Simon
tu es, oder lass es