Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/softlion/wheelpicker-samples
WheelPicker control samples for .NET8 / Maui
https://github.com/softlion/wheelpicker-samples
wheel wheel-picker xamarin xamarin-android xamarin-forms xamarin-ios
Last synced: 2 months ago
JSON representation
WheelPicker control samples for .NET8 / Maui
- Host: GitHub
- URL: https://github.com/softlion/wheelpicker-samples
- Owner: softlion
- Created: 2017-04-09T09:13:45.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-27T07:12:30.000Z (5 months ago)
- Last Synced: 2024-08-27T08:32:30.380Z (5 months ago)
- Topics: wheel, wheel-picker, xamarin, xamarin-android, xamarin-forms, xamarin-ios
- Homepage:
- Size: 2.04 MB
- Stars: 17
- Watchers: 7
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
| Maui (net8), Xamarin Forms, Native (xamarin & .net8) - iOS + Android |
|:------------------------------------------------------------------------------------------------:|
| [![NuGet][nuget-img]][nuget-link] ![Nuget](https://img.shields.io/nuget/dt/Vapolia.WheelPicker) |
| [![][demo-img]][demo-link] |# Wheel Picker
Definition from Apple 🍏 :
A **Wheel Picker** is a **view** that uses a **spinning-wheel** or slot-machine **metaphor** to **display** one or more **sets of values**.This interactive UI control mimics a slot machine user interface on Android, while on iOS, it makes it easy to use multi-wheel pickers.
Enterprise support available: [contact sales](https://vapolia.eu)
Source code available: [contact sales](https://vapolia.eu)## UI controls
* Maui net8 / Xamarin Forms / Android+iOS: `WheelPicker` (hot reload & trimming enabled)
* net8-android & Xamarin Android: `vapolia.WheelPicker` (can be used in layout .xml files)
* net8-ios & Xamarin iOS: `UIPickerViewModel` (can be used in storyboards)## Video presentations
[![Preview][video-img]][video-link]
[![Preview][video-img2]][video-link2][video-img]: https://i.vimeocdn.com/video/668500920.webp?mw=400&mh=540
[video-link]: https://vimeo.com/244170732
[nuget-img]: https://img.shields.io/nuget/v/Vapolia.WheelPicker
[nuget-link]: https://www.nuget.org/packages/Vapolia.WheelPicker/
[nuget-link-forms]: https://www.nuget.org/packages/Vapolia.WheelPicker.Forms/
[demo-img]: https://img.shields.io/badge/demo-source%20code-lightgrey.svg
[demo-link]: https://github.com/softlion/WheelPicker-Samples/tree/master/Demos
[video-img2]: https://i.imgur.com/BKTYa8G.png
[video-link2]: https://vimeo.com/488497139## Quick start
#### Install the nuget package
`dotnet add package Vapolia.WheelPicker`
#### MAUI Specific
If using Maui, register the control in the `CreateMauiApp()` function:
```cs
...
using Vapolia.WheelPickers;...
builder
.UseMauiApp()
.UseWheelPicker();
```#### Add a WheelPicker to your xaml UI
- Add `xmlns:wp="https://vapolia.eu/WheelPicker"` to the root tag
- Add a minimal wheel:```xml
```
## Anatomy of the control
The WheelPicker is made of 2 parts:
- the container ` ... ` which contains 1 or more wheels and present them like a Horizontal StackLayout does.
- a list of 1 or more `wp:WheelDefinition`, each representing a vertical interactive wheel.
Trick: `wp:WheelDefinition` has a customizable template to display each item of the wheel.The WheelPicker is bound to a single data source through `ItemsSource="{Binding SomeProperty}"`.
The type of `SomeProperty` can be:
- For 1 wheel:
- a list of items `IReadOnlyCollection`. Ex: `List`- For more than 1 wheel:
- a list of list of items `IReadOnlyCollection>`. Ex: `List>`
- Each inner list is bound to a wheel.
The outer list must have a number of items equal to the number of `wp:WheelDefinition`.## Full example
```xml
```
In the code behind, set the binding context to your view model containing the items to display.
For the example below `ItemsSource` is bound to a list of strings.```cs
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = new MainPageModel();
}
}public class MainPageModel
{
public List Days { get; } = new () { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };public Command ItemSelectedCommand { get; }
public MainPageModel()
{
//Component is the index of the wheel triggering the command.
//Row is the index of the currently displayed item at the center of the wheel for this Component.
//ItemIndexes are the current indexes of all wheels of the WheelPicker control
ItemSelectedCommand = new Command<(int Component, int Row, IList ItemIndexes)>(tuple =>
{
var selectedValue = Days[tuple.Row];
//...
});
}
}
```## Using custom templates
You can customize how each item is rendered by using custom templates.
By default, the control converts all items to strings and renders those strings with the specified style.You can fully customize the style and content of the items. However, there is a constraint: there is only one template per wheel, which renders all items of that wheel.
If you have multiple wheels in the same WheelPicker, you can set one template per wheel.For example, below is a templated picker with 3 wheels. All properties are bindable and can be dynamically changed.
Note how `SelectedItemsIndex` is used to initialize the position of the 3 wheels to the specified item indexes.
```xml
```
## Some examples
Those examples are extracted from the demo projects in this repository.
A simple picker with one wheel:
```xml
```
A templated picker with one wheel:
```xml
```
A picker with 3 wheels:
The width of the center wheel is computed automatically, and items are aligned differently inside each wheel.```xml
```
A templated picker with 3 wheels:
All properties are bindable and can be dynamically changed.```xml
```
## Reference (Maui & Xamarin Forms)
Click to expand**WheelPicker**
Definition
- `IList` **`WheelDefinitions`** Default Content
- `object` **`ItemsSource`** Accepts both `IReadOnlyCollection` and `IReadOnlyCollection>`Appearance
- `double` **`HorizontalSpaceBetweenWheels`**
- `Color` **`SelectionLinesColor`**Item appearance (used by the default item template, when no custom item template is specified)
- `Font` **`ItemTextFont`**
- `Color` **`ItemTextColor`**
- `Color` **`ItemTextSelectedColor`**Selection
- `IList` **`SelectedItemsIndex`** One index per wheel.
- `ICommand` **`Command`** Triggered when any of the wheel's index has changed
- `EventHandler` **`SelectedItemIndexChanged`** Triggered when any of the wheel's index has changed
- `void` **`Spin`**`(int items, int wheelIndex = 0)` items: the number of item to spin`SelectedItemsIndex` is a list of integers, where each integer represents the selected index within a wheel. In XAML, you can use a space- or comma-separated string of integers.
**WheelDefinition**
- `GridLength` **`Width`**
- `WheelItemAlign` **`HorizontalOptions`**
- `WheelItemAlign` **`Alignment`**
- `bool` **`IsCircular`**
- `DataTemplate` **`ImageItemTemplate`**
- `double` **`RowHeight`**When a wheel's `Width` is set to `Auto`, the control computes the max width of all strings in the data source (if object are strings). When set to `*` (star), the width of the wheel will be proportional to the remaining space. See the `Grid` control for more information about `GridLength`.
`HorizontalOptions` is used to align a wheel inside the available width of the WheelPicker, if it is larger than the width of the wheel.
`Alignment` is used to align the items within a wheel.
## Reference (net8-android & Xamarin.Android)
Click to expandSample usage in axml:
```xml
```
```csharp
var wheelView = FindViewById(Resource.Id.wheelView);
wheelView.SelectedItemIndexChanged += (sender, args) =>
{
var text = $"Wheel {args.WheelIndex} selection changed to item index {args.SelectedItemIndex}";
};
wheelView.ItemsSource = new List { "Monday", "Tuesday", "Wednesday" };
wheelView.SelectedItemsIndex = new [] { 0 };
```**vapolia.WheelPicker**
Definition
- object ItemsSource (either IReadOnlyCollection<T> or IReadOnlyCollection<IReadOnlyCollection<T>>)
- IReadOnlyCollection<T> ItemsSourceSimple (shortcut for ItemsSourceMulti with one wheel)
- IReadOnlyCollection<IReadOnlyCollection<T>> ItemsSourceMulti
- int VisibleItemCountWheelPicker Appearance
- float HorizontalSpaceBetweenWheels
- float VerticalSpaceBetweenItems
- float ItemTextSize
- Typeface ItemTextTypeface
- Color ItemTextColor
- Color ItemTextSelectedColor
- bool ShowSelectionLines
- float SelectionLinesThickness
- Color SelectionLinesColor
- bool HasFadingItems
- bool IsCurvedAppearance of a wheel (a picker can have multiple wheels)
- string ItemWidths (width of each wheel, see ItemWidths chapter below)
- IList<GravityFlags> Gravities
- GravityFlags Gravity (shortcut for Gravities[0], used only when ItemWidths is set)
- IList ItemHeightsAppearance of items inside a wheel
- IList Alignments (same as gravities. Uses WheelItemAlign instead of GravityFlags)
- WheelItemAlign ItemAlign (shortcut for ItemAligns[0])
- IList ItemAlignsSelection
- ICommand SelectedItemIndexChangedCommand
- EventHandler<WheelChangedEventArgs> SelectedItemIndexChanged
- int SelectedItemIndex (shortcut for SelectedItemsIndex[0])
- IList<int> SelectedItemsIndexTemplating
- ItemsSimpleTemplates (currently reserved, used by the renderer)`SelectedItemsIndex` is a list of integers. Each integer represents the selected index within a wheel.
`ItemWidths`: see chapter below
`Alignments` or `Gravities` is used to align a wheel inside the available WheelPicker's width, if it is larger than the width of the wheel.
`ItemAligns` is used to align the items within a wheel.## Reference (net8-ios & Xamarin.iOS)
Click to expand
On iOS, this library utilizes the native UIPickerView along with a custom UIPickerViewModel to significantly simplify the use of this control.
Sample usage:
```csharp
var picker = new UIPickerView {ShowSelectionIndicator = true, BackgroundColor = UIColor.White};
var pickerViewModel = new WheelPickerModel(picker);
picker.Model = pickerViewModel;pickerViewModel.ItemsSource = new [] { "Monday", "Tuesday", "Wednesday" };
pickerViewModel.SelectedItemsIndex = new [] { 0 };
pickerViewModel.ItemAligns = new List { WheelItemAlign.Left };
```**Vapolia.WheelPickerIos.WheelPickerModel**
Definition
- object ItemsSource (either IReadOnlyCollection<T> or IReadOnlyCollection<IReadOnlyCollection<T>>)
- IReadOnlyCollection<T> ItemsSourceSimple (shortcut for ItemsSourceMulti with one wheel)
- IReadOnlyCollection<IReadOnlyCollection<T>> ItemsSourceMultiAppearance
- nfloat HorizontalSpaceBetweenWheelsItem appearance
- string ItemWidths
- UIFont ItemFont
- UIColor ItemTextColor
- IList Alignments
- IList ItemAlignsSelection
- ICommand SelectedItemIndexChangedCommand
- int SelectedItemIndex (shortcut for SelectedItemsIndex[0])
- IEnumerable SelectedItemsIndexTemplating
- ItemsSimpleTemplates (currently reserved, used by the renderer)`SelectedItemsIndex` is a list of integer. Each integer represents the selected index inside a wheel.
`ItemWidths`: see chapter below
`Alignments` is used to align a wheel inside the available WheelPicker's width, if it is larger than the wheel's width.
`ItemAligns` is used to align the items inside a wheel.## ItemWidths (net8-android and net8-ios only, excluding Maui & Xamarn Forms)
Click to expand
`ItemWidths` is used to choose the width of each wheel. It is a space separated string consisting of a combination of float numbers, stars (optionally prepended with a float number), or the "Auto" string.
The total width of the WheelPicker is distributed between the wheels by respecting either :- float number: the exact width
- Auto: the width of the largest string in ItemsSource for a given wheel (if ItemsSource contains strings)
- star: the remaining space not assigned by the above rules, distributed among the other wheels using the optional float number as a weightExamples of ItemWidths:
- `"*"`: one wheel having the full width of WheelPicker
- `"* *"`: two wheels, each of the same width, exactly half of the width of the Wheel Picker
- `"* * *"`: three wheels, each of the same width, exactly one third of the width of the Wheel Picker
- `"100 2* *"`: three wheels, first has a `100` device pixel width, second is twice the size of the third, and `3*-100=width` of the WheelPicker, which resolves to `*=WheelPickerWidth-100`
- `"* Auto *"`: three wheels, the middle wheel's width is computed from the largest string in its items source (if items source contains strings).### Supported Platforms
- Maui, net8-iOS, net8-Android, Xamarin Forms
- Android api level 15+ (Android 4.0.3+)
- iOS 8+### Mvvm friendly
The Wheel Picker provides an event and a Command when the selection changes, making it easy to use with or without mvvm frameworks.
It also implements `INotifyPropertyChanged`.### Live Preview
This control supports hot reload and live preview.### Commercial Support
[Enterprise support is available: contact sales](https://vapolia.eu)
[Source code is available: contact sales](https://vapolia.eu)