/// <summary> /// Update /// </summary> /// <param name="value"></param> private static void Update(DependencyObject obj, DependencyPropertyChangedEventArgs e) { Flipper flipper = (Flipper)obj; flipper.To = (string)e.NewValue; if (flipper.From != null) { if (flipper.From != flipper.To) { flipper.TextBlockTop.Text = flipper.TextBlockFlipBottom.Text = flipper.To; flipper.TextBlockFlipTop.Text = flipper.From; flipper.FlipAnimation.Begin(); flipper.FlipAnimation.Completed -= (s, ev) => { }; flipper.FlipAnimation.Completed += (s, ev) => flipper.TextBlockBottom.Text = flipper.From; } } if (flipper.From == null) { flipper.TextBlockFlipTop.Text = flipper.TextBlockBottom.Text = flipper.To; } flipper.From = flipper.To; }
/// <summary> /// Add /// </summary> /// <param name="name"></param> private void Add(string name) { Flipper flipper = new Flipper() { Tag = name }; flipper.SetBinding(Flipper.ForegroundProperty, new Binding() { Path = new PropertyPath(nameof(Foreground)), Mode = BindingMode.TwoWay, Source = this }); FrameworkElement element = flipper; if (name == null) { element = new Canvas { Width = 5 }; } this.Children.Add(element); }