Class FortuneWheel
A circular fortune wheel control that can be spun to select random items. Supports keyboard interaction (Space or Enter to spin) and full accessibility.
public class FortuneWheel : TemplatedControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue
- Inheritance
-
AvaloniaObjectAnimatableStyledElementVisualLayoutableInteractiveInputElementControlTemplatedControlFortuneWheel
- Implements
-
IDataContextProviderILogicalIThemeVariantHostIResourceHostIResourceNodeIStyleHostISetLogicalParentISetInheritanceParentIStyleableINamedIInputElementIDataTemplateHostISetterValue
- Inherited Members
-
TemplatedControl.BackgroundPropertyTemplatedControl.BackgroundSizingPropertyTemplatedControl.BorderBrushPropertyTemplatedControl.BorderThicknessPropertyTemplatedControl.CornerRadiusPropertyTemplatedControl.FontFamilyPropertyTemplatedControl.FontFeaturesPropertyTemplatedControl.FontSizePropertyTemplatedControl.FontStylePropertyTemplatedControl.FontWeightPropertyTemplatedControl.FontStretchPropertyTemplatedControl.ForegroundPropertyTemplatedControl.PaddingPropertyTemplatedControl.TemplatePropertyTemplatedControl.IsTemplateFocusTargetPropertyTemplatedControl.TemplateAppliedEventTemplatedControl.GetIsTemplateFocusTarget(Control)TemplatedControl.ApplyTemplate()TemplatedControl.GetTemplateFocusTarget()TemplatedControl.OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs)TemplatedControl.OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs)TemplatedControl.OnApplyTemplate(TemplateAppliedEventArgs)TemplatedControl.OnTemplateChanged(AvaloniaPropertyChangedEventArgs)TemplatedControl.BackgroundTemplatedControl.BackgroundSizingTemplatedControl.BorderBrushTemplatedControl.BorderThicknessTemplatedControl.CornerRadiusTemplatedControl.FontFamilyTemplatedControl.FontFeaturesTemplatedControl.FontSizeTemplatedControl.FontStyleTemplatedControl.FontWeightTemplatedControl.FontStretchTemplatedControl.ForegroundTemplatedControl.PaddingTemplatedControl.TemplateTemplatedControl.TemplateAppliedControl.FocusAdornerPropertyControl.TagPropertyControl.ContextMenuPropertyControl.ContextFlyoutPropertyControl.RequestBringIntoViewEventControl.ContextRequestedEventControl.LoadedEventControl.UnloadedEventControl.SizeChangedEventControl.OnLoaded(RoutedEventArgs)Control.OnUnloaded(RoutedEventArgs)Control.OnSizeChanged(SizeChangedEventArgs)Control.OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs)Control.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs)Control.OnGotFocus(GotFocusEventArgs)Control.OnLostFocus(RoutedEventArgs)Control.OnCreateAutomationPeer()Control.OnPointerReleased(PointerReleasedEventArgs)Control.OnKeyUp(KeyEventArgs)Control.FocusAdornerControl.DataTemplatesControl.ContextMenuControl.ContextFlyoutControl.IsLoadedControl.TagControl.ContextRequestedControl.LoadedControl.UnloadedControl.SizeChangedInputElement.FocusablePropertyInputElement.IsEnabledPropertyInputElement.IsEffectivelyEnabledPropertyInputElement.CursorPropertyInputElement.IsKeyboardFocusWithinPropertyInputElement.IsFocusedPropertyInputElement.IsHitTestVisiblePropertyInputElement.IsPointerOverPropertyInputElement.IsTabStopPropertyInputElement.GotFocusEventInputElement.LostFocusEventInputElement.KeyDownEventInputElement.KeyUpEventInputElement.TabIndexPropertyInputElement.TextInputEventInputElement.TextInputMethodClientRequestedEventInputElement.PointerEnteredEventInputElement.PointerExitedEventInputElement.PointerMovedEventInputElement.PointerPressedEventInputElement.PointerReleasedEventInputElement.PointerCaptureLostEventInputElement.PointerWheelChangedEventInputElement.TappedEventInputElement.HoldingEventInputElement.DoubleTappedEventInputElement.Focus(NavigationMethod, KeyModifiers)InputElement.OnAccessKey(RoutedEventArgs)InputElement.OnTextInput(TextInputEventArgs)InputElement.OnPointerEntered(PointerEventArgs)InputElement.OnPointerExited(PointerEventArgs)InputElement.OnPointerMoved(PointerEventArgs)InputElement.OnPointerPressed(PointerPressedEventArgs)InputElement.OnPointerCaptureLost(PointerCaptureLostEventArgs)InputElement.OnPointerWheelChanged(PointerWheelEventArgs)InputElement.UpdateIsEffectivelyEnabled()InputElement.FocusableInputElement.IsEnabledInputElement.CursorInputElement.IsKeyboardFocusWithinInputElement.IsFocusedInputElement.IsHitTestVisibleInputElement.IsPointerOverInputElement.IsTabStopInputElement.IsEffectivelyEnabledInputElement.TabIndexInputElement.KeyBindingsInputElement.IsEnabledCoreInputElement.GestureRecognizersInputElement.GotFocusInputElement.LostFocusInputElement.KeyDownInputElement.KeyUpInputElement.TextInputInputElement.TextInputMethodClientRequestedInputElement.PointerEnteredInputElement.PointerExitedInputElement.PointerMovedInputElement.PointerPressedInputElement.PointerReleasedInputElement.PointerCaptureLostInputElement.PointerWheelChangedInputElement.TappedInputElement.HoldingInputElement.DoubleTappedInteractive.RaiseEvent(RoutedEventArgs)Interactive.BuildEventRoute(RoutedEvent)Layoutable.DesiredSizePropertyLayoutable.WidthPropertyLayoutable.HeightPropertyLayoutable.MinWidthPropertyLayoutable.MaxWidthPropertyLayoutable.MinHeightPropertyLayoutable.MaxHeightPropertyLayoutable.MarginPropertyLayoutable.HorizontalAlignmentPropertyLayoutable.VerticalAlignmentPropertyLayoutable.UseLayoutRoundingPropertyLayoutable.UpdateLayout()Layoutable.Measure(Size)Layoutable.Arrange(Rect)Layoutable.InvalidateMeasure()Layoutable.InvalidateArrange()Layoutable.AffectsMeasure<T>(params AvaloniaProperty[])Layoutable.AffectsArrange<T>(params AvaloniaProperty[])Layoutable.MeasureCore(Size)Layoutable.MeasureOverride(Size)Layoutable.ArrangeCore(Rect)Layoutable.ArrangeOverride(Size)Layoutable.OnMeasureInvalidated()Layoutable.OnVisualParentChanged(Visual, Visual)Layoutable.WidthLayoutable.HeightLayoutable.MinWidthLayoutable.MaxWidthLayoutable.MinHeightLayoutable.MaxHeightLayoutable.MarginLayoutable.HorizontalAlignmentLayoutable.VerticalAlignmentLayoutable.DesiredSizeLayoutable.IsMeasureValidLayoutable.IsArrangeValidLayoutable.UseLayoutRoundingLayoutable.EffectiveViewportChangedLayoutable.LayoutUpdatedVisual.BoundsPropertyVisual.ClipToBoundsPropertyVisual.ClipPropertyVisual.IsVisiblePropertyVisual.OpacityPropertyVisual.OpacityMaskPropertyVisual.EffectPropertyVisual.HasMirrorTransformPropertyVisual.RenderTransformPropertyVisual.RenderTransformOriginPropertyVisual.FlowDirectionPropertyVisual.VisualParentPropertyVisual.ZIndexPropertyVisual.GetFlowDirection(Visual)Visual.SetFlowDirection(Visual, FlowDirection)Visual.InvalidateVisual()Visual.AffectsRender<T>(params AvaloniaProperty[])Visual.OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)Visual.InvalidateMirrorTransform()Visual.BoundsVisual.ClipToBoundsVisual.ClipVisual.IsEffectivelyVisibleVisual.IsVisibleVisual.OpacityVisual.OpacityMaskVisual.EffectVisual.HasMirrorTransformVisual.RenderTransformVisual.RenderTransformOriginVisual.FlowDirectionVisual.ZIndexVisual.VisualChildrenVisual.VisualRootVisual.BypassFlowDirectionPoliciesVisual.AttachedToVisualTreeVisual.DetachedFromVisualTreeStyledElement.DataContextPropertyStyledElement.NamePropertyStyledElement.ParentPropertyStyledElement.TemplatedParentPropertyStyledElement.ThemePropertyStyledElement.BeginInit()StyledElement.EndInit()StyledElement.ApplyStyling()StyledElement.InitializeIfNeeded()StyledElement.OnDataContextBeginUpdate()StyledElement.OnDataContextEndUpdate()StyledElement.OnInitialized()StyledElement.NameStyledElement.ClassesStyledElement.DataContextStyledElement.IsInitializedStyledElement.StylesStyledElement.StyleKeyStyledElement.ResourcesStyledElement.TemplatedParentStyledElement.ThemeStyledElement.LogicalChildrenStyledElement.PseudoClassesStyledElement.StyleKeyOverrideStyledElement.ParentStyledElement.ActualThemeVariantStyledElement.AttachedToLogicalTreeStyledElement.DetachedFromLogicalTreeStyledElement.DataContextChangedStyledElement.InitializedStyledElement.ResourcesChangedStyledElement.ActualThemeVariantChangedAnimatable.TransitionsPropertyAnimatable.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs)Animatable.TransitionsAvaloniaObject.CheckAccess()AvaloniaObject.VerifyAccess()AvaloniaObject.ClearValue(AvaloniaProperty)AvaloniaObject.ClearValue<T>(AvaloniaProperty<T>)AvaloniaObject.ClearValue<T>(StyledProperty<T>)AvaloniaObject.ClearValue<T>(DirectPropertyBase<T>)AvaloniaObject.GetHashCode()AvaloniaObject.GetValue(AvaloniaProperty)AvaloniaObject.GetValue<T>(StyledProperty<T>)AvaloniaObject.GetValue<T>(DirectPropertyBase<T>)AvaloniaObject.GetBaseValue<T>(StyledProperty<T>)AvaloniaObject.IsAnimating(AvaloniaProperty)AvaloniaObject.IsSet(AvaloniaProperty)AvaloniaObject.SetValue<T>(StyledProperty<T>, T, BindingPriority)AvaloniaObject.SetValue<T>(DirectPropertyBase<T>, T)AvaloniaObject.SetCurrentValue<T>(StyledProperty<T>, T)AvaloniaObject.Bind(AvaloniaProperty, IBinding)AvaloniaObject.CoerceValue(AvaloniaProperty)AvaloniaObject.RaisePropertyChanged<T>(DirectPropertyBase<T>, T, T)AvaloniaObject.SetAndRaise<T>(DirectPropertyBase<T>, ref T, T)AvaloniaObject.InheritanceParentAvaloniaObject.this[AvaloniaProperty]AvaloniaObject.this[IndexerDescriptor]AvaloniaObject.PropertyChanged
Constructors
FortuneWheel()
Initializes a new instance of the FortuneWheel class.
public FortuneWheel()
Fields
AnimationDurationProperty
Defines the AnimationDuration property.
public static readonly StyledProperty<TimeSpan> AnimationDurationProperty
Field Value
- StyledProperty<TimeSpan>
CenterFillProperty
Defines the CenterFill property.
public static readonly StyledProperty<IBrush?> CenterFillProperty
Field Value
- StyledProperty<IBrush>
CenterRadiusProperty
Defines the CenterRadius property.
public static readonly StyledProperty<double> CenterRadiusProperty
Field Value
- StyledProperty<double>
IndicatorFillProperty
Defines the IndicatorFill property.
public static readonly StyledProperty<IBrush?> IndicatorFillProperty
Field Value
- StyledProperty<IBrush>
IndicatorPositionProperty
Defines the IndicatorPosition property.
public static readonly StyledProperty<IndicatorPosition> IndicatorPositionProperty
Field Value
- StyledProperty<IndicatorPosition>
IndicatorSizeProperty
Defines the IndicatorSize property.
public static readonly StyledProperty<double> IndicatorSizeProperty
Field Value
- StyledProperty<double>
IsSpinningProperty
Defines the IsSpinning property.
public static readonly DirectProperty<FortuneWheel, bool> IsSpinningProperty
Field Value
- DirectProperty<FortuneWheel, bool>
ItemsProperty
Defines the Items property.
public static readonly StyledProperty<ObservableCollection<FortuneItem>> ItemsProperty
Field Value
- StyledProperty<ObservableCollection<FortuneItem>>
MinimumSpinsProperty
Defines the MinimumSpins property.
public static readonly StyledProperty<int> MinimumSpinsProperty
Field Value
- StyledProperty<int>
RotationAngleProperty
Defines the RotationAngle property.
public static readonly StyledProperty<double> RotationAngleProperty
Field Value
- StyledProperty<double>
SelectedIndexProperty
Defines the SelectedIndex property.
public static readonly StyledProperty<int> SelectedIndexProperty
Field Value
- StyledProperty<int>
ShowIndicatorProperty
Defines the ShowIndicator property.
public static readonly StyledProperty<bool> ShowIndicatorProperty
Field Value
- StyledProperty<bool>
StyleStrategyProperty
Defines the StyleStrategy property.
public static readonly StyledProperty<IStyleStrategy> StyleStrategyProperty
Field Value
- StyledProperty<IStyleStrategy>
Properties
AnimationDuration
Gets or sets the duration of the spin animation.
public TimeSpan AnimationDuration { get; set; }
Property Value
CenterFill
Gets or sets the fill brush for the center circle.
public IBrush? CenterFill { get; set; }
Property Value
- IBrush
CenterRadius
Gets or sets the radius of the center circle.
public double CenterRadius { get; set; }
Property Value
IndicatorFill
Gets or sets the fill brush for the indicator.
public IBrush? IndicatorFill { get; set; }
Property Value
- IBrush
IndicatorPosition
Gets or sets the position of the indicator.
public IndicatorPosition IndicatorPosition { get; set; }
Property Value
IndicatorSize
Gets or sets the size of the indicator.
public double IndicatorSize { get; set; }
Property Value
IsSpinning
Gets a value indicating whether the wheel is currently spinning.
public bool IsSpinning { get; }
Property Value
Items
Gets or sets the collection of items to display on the wheel.
public ObservableCollection<FortuneItem> Items { get; set; }
Property Value
MinimumSpins
Gets or sets the minimum number of full rotations during a spin.
public int MinimumSpins { get; set; }
Property Value
RotationAngle
Gets or sets the current rotation angle of the wheel in degrees.
public double RotationAngle { get; set; }
Property Value
SelectedIndex
Gets or sets the index of the currently selected item.
public int SelectedIndex { get; set; }
Property Value
ShowIndicator
Gets or sets whether to show the indicator pointer.
public bool ShowIndicator { get; set; }
Property Value
StyleStrategy
Gets or sets the strategy used to style individual items.
public IStyleStrategy StyleStrategy { get; set; }
Property Value
Methods
CancelAnimation()
Cancels any running animation and cleans up resources.
public void CancelAnimation()
OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is removed from a rooted visual tree.
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
eVisualTreeAttachmentEventArgsThe event args.
OnKeyDown(KeyEventArgs)
Invoked when an unhandled Avalonia.Input.InputElement.KeyDownEvent reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
protected override void OnKeyDown(KeyEventArgs e)
Parameters
eKeyEventArgsData about the event.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
changeAvaloniaPropertyChangedEventArgsThe property change details.
Render(DrawingContext)
Renders the visual to a Avalonia.Media.DrawingContext.
public override void Render(DrawingContext context)
Parameters
contextDrawingContextThe drawing context.
SpinAsync()
Spins the wheel to a random item.
public Task SpinAsync()
Returns
- Task
A task that completes when the spin animation finishes.
SpinToAsync(int)
Spins the wheel to a specific item index.
public Task SpinToAsync(int targetIndex)
Parameters
targetIndexintThe index of the target item.
Returns
- Task
A task that completes when the spin animation finishes.
Events
SpinCompleted
Occurs when a spin animation completes.
public event EventHandler<FortuneSelectionEventArgs>? SpinCompleted
Event Type
SpinStarted
Occurs when a spin animation starts.
public event EventHandler<FortuneSelectionEventArgs>? SpinStarted