/// <inheritdoc/> public override void OnApplyTemplate() { base.OnApplyTemplate(); increaseButton = GetTemplateChild("PART_IncreaseButton") as RepeatButton; if (increaseButton == null) { throw new InvalidOperationException("A part named 'PART_IncreaseButton' must be present in the ControlTemplate, and must be of type 'RepeatButton'."); } decreaseButton = GetTemplateChild("PART_DecreaseButton") as RepeatButton; if (decreaseButton == null) { throw new InvalidOperationException("A part named 'PART_DecreaseButton' must be present in the ControlTemplate, and must be of type 'RepeatButton'."); } contentHost = GetTemplateChild("PART_ContentHost") as ScrollViewer; if (contentHost == null) { throw new InvalidOperationException("A part named 'PART_ContentHost' must be present in the ControlTemplate, and must be of type 'ScrollViewer'."); } var increasePressedWatcher = new DependencyPropertyWatcher(increaseButton); increasePressedWatcher.RegisterValueChangedHandler(ButtonBase.IsPressedProperty, RepeatButtonIsPressedChanged); var decreasePressedWatcher = new DependencyPropertyWatcher(decreaseButton); decreasePressedWatcher.RegisterValueChangedHandler(ButtonBase.IsPressedProperty, RepeatButtonIsPressedChanged); var textValue = FormatValue(Value); SetCurrentValue(TextProperty, textValue); contentHost.QueryCursor += HostQueryCursor; }
/// <inheritdoc/> protected override void OnApplyTemplate() { isEnabledWatcher = new DependencyPropertyWatcher <bool>(this, nameof(IsEnabled)); isEnabledWatcher.PropertyChanged += IsEnabledWatcher_PropertyChanged; CheckIsEnabled(); base.OnApplyTemplate(); }
public MaterialSwitch() { InitializeComponent(); _on = new DoubleAnimation(20, _animationDuration) { EasingFunction = new QuadraticEase() }; _off = new DoubleAnimation(0, _animationDuration) { EasingFunction = new QuadraticEase() }; _fillOn = new ColorAnimation(_onColor, _animationDuration) { EasingFunction = new QuadraticEase() }; _fillOff = new ColorAnimation(_offColor, _animationDuration) { EasingFunction = new QuadraticEase() }; _backFillOff = new ColorAnimation(_backOffColor, _animationDuration) { EasingFunction = new QuadraticEase() }; SwitchHead.RenderTransform = new TranslateTransform(0, 0); SwitchHead.Fill = new SolidColorBrush(_offColor); SwitchBack.Fill = new SolidColorBrush(_backOffColor); _dpw = new DependencyPropertyWatcher <bool>(this, "Status"); _dpw.PropertyChanged += StatusWatcher_PropertyChanged; }
/// <summary> /// Prepares this class to apply delays base on source property value changes. /// </summary> /// <param name="source">A source object to assess.</param> private void Initialize(object source) { if (initialized) { return; } // If source is resolved then set binding up: if (source != null) { // Build a fake dependency object to receive binding notifications: bindingWatcher = new DependencyPropertyWatcher <object>(source, InnerBinding.Path); bindingWatcherDescriptor = DependencyPropertyDescriptor.FromProperty(DependencyPropertyWatcher <object> .ValueProperty, typeof(DependencyPropertyWatcher <object>)); bindingWatcherDescriptor.AddValueChanged(bindingWatcher, BindingWatcher_SourcePropertyChanged); initialized = true; // Check if source is a datacontext, in which case subscribe to datacontext changed event: if (IsInnerSourceDatacontext && TargetObject != null) { (TargetObject as FrameworkElement).DataContextChanged += DatacontextTarget_DataContextChanged; } } }
public Toasts() { this.InitializeComponent(); (this.Content as FrameworkElement).DataContext = this; watcher = new DependencyPropertyWatcher <DahuNotification>(this.DahuNotificationTextBox, "Text"); watcher.PropertyChanged += NotificationNotif; }
public DahuButton3() { this.InitializeComponent(); (this.Content as FrameworkElement).DataContext = this; watcher = new DependencyPropertyWatcher <string>(this.ProgressBarIsBusy, "IsIndeterminate"); watcher.PropertyChanged += ProgressBarIsBusyChanged; }
/// <summary> /// Initiates tracking of the bound path binding value to update Path /// when the binding updates the target object (this class). /// </summary> private void StartTrackingPathBindingUpdates() { if (boundPathBindingWatcher == null && boundPathSource != null) { boundPathBindingWatcher = new DependencyPropertyWatcher <object>(boundPathSource, PathValueBinding.Path); boundPathBindingWatcher.PropertyChanged += BoundPathBindingWatcher_PropertyChanged; } }
public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs args) { DependencyPropertyWatcher <T> source = (DependencyPropertyWatcher <T>)sender; if (source.PropertyChanged != null) { source.PropertyChanged(source.Target, args); } }
/// <summary> /// Stops tracking path binding updates and release related resources. /// </summary> private void StopTrackingPathBindingUpdates() { if (boundPathBindingWatcher != null) { boundPathBindingWatcher.PropertyChanged -= BoundPathBindingWatcher_PropertyChanged; boundPathBindingWatcher.Dispose(); boundPathBindingWatcher = null; } }
private static void SliderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var behavior = (ScaleFromSliderBehavior)d; var slider = (Slider)e.NewValue; slider.LayoutUpdated += behavior.SliderLayoutUpdated; watcher = new DependencyPropertyWatcher(slider); watcher.RegisterValueChangedHandler(RangeBase.MinimumProperty, behavior.SliderLayoutUpdated); watcher.RegisterValueChangedHandler(RangeBase.MaximumProperty, behavior.SliderLayoutUpdated); }
/// <summary> /// Called when the target object is unloaded. /// </summary> /// <param name="target">The binding target object.</param> protected override void OnTargetUnloaded(FrameworkElement target) { target.DataContextChanged -= DatacontextTarget_DataContextChanged; // free up event handlers. delayTimer?.Stop(); if (bindingWatcher != null) { bindingWatcherDescriptor.RemoveValueChanged(bindingWatcher, BindingWatcher_SourcePropertyChanged); bindingWatcher.Dispose(); bindingWatcher = null; } }
private readonly DependencyPropertyWatcher <float> _curValwatcher; //https://blogs.msdn.microsoft.com/flaviencharlon/2012/12/07/getting-change-notifications-from-any-dependency-property-in-windows-store-apps/ public GenericGauge() { InitializeComponent(); _curValwatcher = new DependencyPropertyWatcher <float>(this, "CurrentVal"); _curValwatcher.PropertyChanged += CurValWatcher_PropertyChanged; _a = new DoubleAnimation(0, TimeSpan.FromMilliseconds(AnimTime)) { EasingFunction = new QuadraticEase() }; Bar.RenderTransform = new ScaleTransform(1, 1, 0, .5); }
public NotificationWindow(string caption, string message, ICommand command, object commandParameter) { InitializeComponent(); Caption = caption; Message = message; Command = command; CommandParameter = commandParameter; DataContext = this; var dependencyPropertyWatcher = new DependencyPropertyWatcher(this); dependencyPropertyWatcher.RegisterValueChangedHandler(ActualHeightProperty, (s, e) => SetPosition()); Loaded += NotificationWindowLoaded; }
/// <summary> /// Called whenever the datacontext of target object changed. /// </summary> /// <param name="sender">A framework element for which the property changed.</param> /// <param name="e">Information about the datacontext changed event.</param> private void DatacontextTarget_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (TargetObject == sender && TargetProperty != null) { if (bindingWatcher != null) { bindingWatcherDescriptor.RemoveValueChanged(bindingWatcher, BindingWatcher_SourcePropertyChanged); bindingWatcher.Dispose(); } bindingWatcher = new DependencyPropertyWatcher <object>(BindingHelpers.GetBindingSource(InnerBinding, TargetObject, out bool _, out bool _), InnerBinding.Path); bindingWatcherDescriptor = bindingWatcherDescriptor = DependencyPropertyDescriptor.FromProperty(DependencyPropertyWatcher <object> .ValueProperty, typeof(DependencyPropertyWatcher <object>)); bindingWatcherDescriptor.AddValueChanged(bindingWatcher, BindingWatcher_SourcePropertyChanged); } else if (sender is FrameworkElement casted) { casted.DataContextChanged -= DatacontextTarget_DataContextChanged; } }
private static void ShouldTrackFillChangeChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { Ellipse ellipse = (Ellipse)target; DependencyPropertyWatcher<Brush> watcher = GetEllipseFillWatcher(ellipse); if (watcher != null) { watcher.Dispose(); } if ((bool)args.NewValue) { watcher = new DependencyPropertyWatcher<Brush>(ellipse, "Fill", Ellipse_FillChanged); SetEllipseFillWatcher(ellipse, watcher); } }
private static void SetEllipseFillWatcher(DependencyObject obj, DependencyPropertyWatcher<Brush> value) { obj.SetValue(EllipseFillWatcherProperty, value); }