private void UpdateThumb() { if (_ThumbTranslate != null && _SwitchTrack != null && _ThumbIndicator != null) { double destination = IsChecked.GetValueOrDefault() ? Width - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.Width + _ThumbIndicator.Margin.Left + _ThumbIndicator.Margin.Right) : 0; _thumbAnimation = new Animation.Animation(); //_thumbAnimation.To = destination; _thumbAnimation.Duration = TimeSpan.FromMilliseconds(500); //_thumbAnimation.Easing = new ExponentialEase() { Exponent = 9 }; _thumbAnimation.FillMode = Animation.FillMode.Backward; _thumbAnimation.PropertyChanged += (o, e) => { //if(e.Property.Name== nameof(Animation.Animation.) }; //_ThumbTranslate. //AnimationTimeline currentAnimation = _thumbAnimation; //_thumbAnimation.Completed += (sender, e) => { // if (_thumbAnimation != null && currentAnimation == _thumbAnimation) // { // _ThumbTranslate.X = destination; // _thumbAnimation = null; // } //}; //_ThumbTranslate.BeginAnimation(TranslateTransform.XProperty, _thumbAnimation); } }
private void UpdateThumb() { if (_ThumbTranslate != null && _SwitchTrack != null && _ThumbIndicator != null) { double destination = IsChecked.GetValueOrDefault() ? ActualWidth - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.ActualWidth) : 0; _thumbAnimation = new DoubleAnimation(); _thumbAnimation.To = destination; _thumbAnimation.Duration = TimeSpan.FromMilliseconds(500); _thumbAnimation.EasingFunction = new ExponentialEase() { Exponent = 9 }; _thumbAnimation.FillBehavior = FillBehavior.Stop; AnimationTimeline currentAnimation = _thumbAnimation; _thumbAnimation.Completed += (sender, e) => { if (_thumbAnimation != null && currentAnimation == _thumbAnimation) { _ThumbTranslate.X = destination; _thumbAnimation = null; } }; _ThumbTranslate.BeginAnimation(TranslateTransform.XProperty, _thumbAnimation); } }
protected override void Toggle() { if (!IsChecked.GetValueOrDefault()) { IsChecked = true; } }
protected override void OnChecked(RoutedEventArgs e) { base.OnChecked(e); if (_lockUI == false) { _StateSetter(_State, IsChecked.GetValueOrDefault()); } }
public FlatToggleButton() { InitializeComponent(); DependencyPropertyDescriptor prop = DependencyPropertyDescriptor.FromProperty(IsCheckedProperty, this.GetType()); prop.AddValueChanged(this, (x, y) => SetValue(TextProperty, IsChecked.GetValueOrDefault() ? TextOn ?? "On" : TextOff ?? "Off")); }
void _ThumbIndicator_SizeChanged(object sender, SizeChangedEventArgs e) { if (_ThumbTranslate != null && _SwitchTrack != null && _ThumbIndicator != null) { double destination = IsChecked.GetValueOrDefault() ? _SwitchTrack.ActualWidth - _ThumbIndicator.ActualWidth : 0; _ThumbTranslate.X = destination; } }
void _SwitchTrack_SizeChanged(object sender, SizeChangedEventArgs e) { if (_ThumbTranslate != null && _SwitchTrack != null && _ThumbIndicator != null) { double destination = IsChecked.GetValueOrDefault() ? ActualWidth - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.ActualWidth) : 0; _ThumbTranslate.X = destination; } }
/// <summary> /// Provides derived classes an opportunity to handle changes to the DropDownContextMenu property. /// </summary> protected virtual void OnDropDownContextMenuChanged(DependencyPropertyChangedEventArgs e) { var oldContextMenu = e.OldValue as ContextMenu; if (oldContextMenu != null && IsChecked.GetValueOrDefault()) { oldContextMenu.Closed -= new RoutedEventHandler(OnContextMenuClosed); } }
private void UpdateThumb() { if (_ThumbTranslate != null && _SwitchTrack != null && _ThumbIndicator != null) { double destination = IsChecked.GetValueOrDefault() ? Width - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.Width + _ThumbIndicator.Margin.Left + _ThumbIndicator.Margin.Right) : 0; _ThumbTranslate.X = destination; } }
/// <inheritdoc/> protected override void OnToggle(Boolean toggledByUser) { if (!IsChecked.GetValueOrDefault()) { IsChecked = true; if (toggledByUser) { OnCheckedByUser(); } } }
protected override void OnClick() { if (DropDown != null) { // If there is a drop-down assigned to this button, then position and display it DropDown.PlacementTarget = this; DropDown.Placement = PlacementMode.Bottom; DropDown.IsOpen = !IsChecked.GetValueOrDefault(); } }
void _DraggingThumb_DragStarted(object sender, DragStartedEventArgs e) { if (_ThumbTranslate != null) { _ThumbTranslate.BeginAnimation(TranslateTransform.XProperty, null); double destination = IsChecked.GetValueOrDefault() ? ActualWidth - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.ActualWidth) : 0; _ThumbTranslate.X = destination; _thumbAnimation = null; } _lastDragPosition = _ThumbTranslate.X; _isDragging = false; }
public override void OnApplyTemplate() { InvalidateProperty(IsIconProperty); _path = (Path)GetTemplateChild(@"Path"); if (_path != null) { _iconColorManager = new AnimationStateManager <System.Windows.Media.Animation.ColorAnimation>(_path, @"Fill.Color"); _iconColorManager.AddState(@"Disabled", () => !IsEnabled, DisabledColor); _iconColorManager.AddState(@"Normal", () => IsEnabled && !IsChecked.GetValueOrDefault(), NormalColor); _iconColorManager.AddState(@"Checked", () => IsEnabled && IsChecked.GetValueOrDefault(), CheckedColor); _iconColorManager.Update(); } }
private void SwitchTrack_PropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e) { if (e.Property.Name == nameof(_SwitchTrack.Width) || e.Property.Name == nameof(_SwitchTrack.Height)) { if (_ThumbTranslate != null && _SwitchTrack != null && _ThumbIndicator != null) { double destination = IsChecked.GetValueOrDefault() ? Width - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.Width + _ThumbIndicator.Margin.Left + _ThumbIndicator.Margin.Right) : 0; _ThumbTranslate.X = destination; } } }
protected override void OnInitialized(EventArgs e) { if (Content == null) { Content = _image; // TODO: This control would be a lot more useful if the size wasn't fixed _image.Width = 16; _image.Height = 16; } _image.Source = (IsChecked.GetValueOrDefault(false)) ? CheckedImage : DefaultImage; base.OnInitialized(e); }
/// <summary> /// Toggles the value of the <see cref="IsChecked"/> property. /// </summary> /// <param name="toggledByUser">A value indicating whether this state change was caused by a user interaction.</param> protected virtual void OnToggle(Boolean toggledByUser = false) { var isChecked = IsChecked; if (IsThreeState) { if (isChecked.HasValue) { if (isChecked.Value) { IsChecked = null; if (toggledByUser) { OnIndeterminateByUser(); } } else { IsChecked = true; if (toggledByUser) { OnCheckedByUser(); } } } else { IsChecked = false; if (toggledByUser) { OnUncheckedByUser(); } } } else { IsChecked = !isChecked.GetValueOrDefault(); if (toggledByUser) { if (IsChecked.GetValueOrDefault()) { OnCheckedByUser(); } else { OnUncheckedByUser(); } } } }
private void tabHeader_MouseEnter(object sender, MouseEventArgs e) { if ((!IsChecked.GetValueOrDefault()) && Manager.Config.ShowPreviews) { var preview = new TabPreview() { Frame = ArmModule }; popup = new Popup() { Child = preview, PlacementTarget = this, AllowsTransparency = true }; popup.IsOpen = true; } }
private void _DraggingThumb_DragStarted(object sender, VectorEventArgs e) { if (_DraggingThumb.IsPointerOver == false) { _lastDragPosition = null; _isDragging = false; return; } if (_ThumbTranslate != null) { //_ThumbTranslate.BeginAnimation(TranslateTransform.XProperty, null); double destination = IsChecked.GetValueOrDefault() ? Width - (_SwitchTrack.Margin.Left + _SwitchTrack.Margin.Right + _ThumbIndicator.Width + _ThumbIndicator.Margin.Left + _ThumbIndicator.Margin.Right) : 0; _ThumbTranslate.X = destination; _thumbAnimation = null; } _lastDragPosition = _ThumbTranslate.X; _isDragging = false; }
void _DraggingThumb_DragCompleted(object sender, DragCompletedEventArgs e) { SetIsPressed(false); _lastDragPosition = null; if (!_isDragging) { OnClick(); } else if (_ThumbTranslate != null && _SwitchTrack != null) { if (!IsChecked.GetValueOrDefault() && _ThumbTranslate.X + 6.5 >= _SwitchTrack.ActualWidth / 2) { OnClick(); } else if (IsChecked.GetValueOrDefault() && _ThumbTranslate.X + 6.5 <= _SwitchTrack.ActualWidth / 2) { OnClick(); } UpdateThumb(); } }
private void _DraggingThumb_DragCompleted(object sender, VectorEventArgs e) { _lastDragPosition = null; if (!_isDragging) { OnClick(); } else if (_ThumbTranslate != null && _SwitchTrack != null) { if (!IsChecked.GetValueOrDefault() && _ThumbTranslate.X + 6.5 >= _SwitchTrack.Width / 2) { OnClick(); } else if (IsChecked.GetValueOrDefault() && _ThumbTranslate.X + 6.5 <= _SwitchTrack.Width / 2) { OnClick(); } UpdateThumb(); } _isDragging = false; }
private void OnDragCompleted(object sender, DragCompletedEventArgs e) { _lastDragPosition = null; if (!_isDragging) { OnToggle(); } else if (_thumbTranslate != null && _switchTrack != null) { if (!IsChecked.GetValueOrDefault() && _thumbTranslate.X + 6.5 >= _switchTrack.ActualWidth / 2) { OnToggle(); } else if (IsChecked.GetValueOrDefault() && _thumbTranslate.X + 6.5 <= _switchTrack.ActualWidth / 2) { OnToggle(); } else { UpdateThumb(); } } }
/// <summary> /// Gets the non null value of IsChecked /// </summary> /// <returns>True if a Client has watched the ethical video, otherwise false</returns> public virtual bool HasWatchedEthicalVideo() { return(IsChecked.GetValueOrDefault()); }
private double GetThumbIndicatorDestination() { return(IsChecked.GetValueOrDefault() ? ActualWidth - (_switchTrack.Margin.Left + _switchTrack.Margin.Right + _thumbIndicator.Margin.Left + _thumbIndicator.Margin.Right + _thumbIndicator.ActualWidth) : 0); }
/// <summary> /// Returns the visual used by <see cref="UpdateChildren"/>. /// </summary> /// <remarks> /// Depending on the the <see cref="ToggleButton.IsChecked">toggle state</see>, <see cref="CheckedVisual"/> /// or <see cref="UncheckedVisual"/> is returned. /// </remarks> /// <returns>The visual used by <see cref="UpdateChildren"/>.</returns> protected virtual Visual GetVisual() { return(IsChecked.GetValueOrDefault() ? CheckedVisual : UncheckedVisual); }
void AppBarToggleButton_Click(object sender, RoutedEventArgs e) { VisualStateManager.GoToState(this, IsChecked.GetValueOrDefault() ? "Checked" : "Unchecked", false); }