Back to Devexpress

ToolbarColorSelector Class

maui-devexpress-dot-maui-dot-controls-0ac8a8d3.md

latest11.6 KB
Original Source

ToolbarColorSelector Class

A color selector item within the DXToolbar control.

Namespace : DevExpress.Maui.Controls

Assembly : DevExpress.Maui.Controls.dll

NuGet Package : DevExpress.Maui.Controls

Declaration

csharp
[DXLicenseMAUI]
public class ToolbarColorSelector :
    ToolbarItemBase

Remarks

The ToolbarColorSelector allows you to pick a color from the collection.

Add ToolbarColorSelector to DXToolbar

Use the ItemsSource property to bind the ToolbarColorSelector to a collection of colors that you want to display.

The following code sample displays a ToolbarColorSelector and binds it to a collection of colors:

xaml
<ContentPage ...
             xmlns:local="clr-namespace:ToolbarColorSelectorApp"
             xmlns:dxc="clr-namespace:DevExpress.Maui.Controls;assembly=DevExpress.Maui.Controls">
    <ContentPage.BindingContext>
        <local:MainViewModel/>
    </ContentPage.BindingContext>
    <Grid>
        <dxc:DXToolbar>
            <dxc:ToolbarColorSelector ItemsSource="{Binding Colors}"/>
            <!-- ... -->
        </dxc:DXToolbar>
    </Grid>
</ContentPage>
csharp
namespace ToolbarColorSelectorApp {
    public class MainViewModel {
        public Color[] Colors { get; } = new Color[]{
            Color.FromArgb("#FF0000"),
            Color.FromArgb("#00FF00"),
            Color.FromArgb("#0000FF")
            };
    }
}

Handle Taps

You can use the SelectedColorChanged event to handle a tap on a ToolbarColorSelector item.

You can also use the Command property to specify a command that is invoked when a user taps a ToolbarColorSelector. You can define the CommandParameter property to specify a command’s parameter.

The following code sample creates a command that displays an alert with the text that contains the HEX of the selected item:

xaml
<ContentPage ...
             xmlns:local="clr-namespace:ToolbarColorSelectorApp"/>
    <ContentPage.BindingContext>
        <local:MainViewModel/>
    </ContentPage.BindingContext>
    <Grid>
        <dxc:DXToolbar>
            <dxc:ToolbarColorSelector x:Name="colorselector" Command="{Binding TapItemCommand}" 
                                      CommandParameter="{Binding SelectedColor, Source={x:Reference colorselector}}"/>
            <!-- ... -->
        </dxc:DXToolbar>
    </Grid>
</ContentPage>
csharp
public class MainViewModel: INotifyPropertyChanged {
    public ICommand TapItemCommand { get; set; }
    public MainViewModel() {
        this.TapItemCommand = new Command<Color>(OnItemTap);
    }

    private async void OnItemTap(Color tappedcolor) {
        await Application.Current.MainPage.DisplayAlert("Color Selected", "The "+tappedcolor.ToHex()+" item is tapped", "Ok");
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged( string propertyName = "") {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

When an item is pressed, you can use PressedScale property to specify its scale factor.

Selector Availability

Set the IsEnabled property to false to restrict users to pick an item from the ToolbarColorSelector.

Handle Loading

You can use the following inherited member to handle the ToolbarColorSelector loading:

PropertyDescription
IsLoadedGets or sets whether a DXElementBase descendant is loaded.
LoadedFires when the DXElementBase descendant is loaded.
UnloadedFires when the DXElementBase descendant is unloaded.

Customize Appearance

You can use the following properties to customize common ToolbarColorSelector appearance settings:

PropertyDescription
CornerRadiusGets or sets the corner radius of ToolbarColorSelector. This is a bindable property.
MarginGets or sets margins of the ToolbarColorSelector. This is a bindable property.
PaddingGest or sets paddings of the ToolbarColorSelector. This is a bindable property.
SpacingGets or sets the spacing between the ToolbarColorSelector items. This is a bindable property.
HeightRequestGets or sets height of the ToolbarColorSelector. This is a bindable property.
MaximumHeightRequestGets or sets the maximum height of the ToolbarColorSelector. This is a bindable property.
MinimumHeightRequestGets or sets the minimum height of the ToolbarColorSelector. This is a bindable property.
WidthRequestGets or sets the width of the ToolbarColorSelector. This is a bindable property.
MaximumWidthRequestGets or sets the maximum width of the ToolbarColorSelector. This is a bindable property.
MinimumWidthRequestGets or sets the minimum width of the ToolbarColorSelector. This is a bindable property.
HorizontalOptionsGets or sets the horizontal alignment of a ToolbarColorSelector. This is a bindable property.
VerticalOptionsGets or sets the vertical alignment of the ToolbarColorSelector. This is a bindable property.
BackgroundColorGets or sets the ToolbarColorSelector background color. This is a bindable property.
BorderColorGets or sets the color of the ToolbarColorSelector border. This is a bindable property.
BorderThicknessGets or sets thickness of the ToolbarColorSelector border. This is a bindable property.
StyleGets or sets the style applied to a DXElementBase descendant. This is a bindable property.

Item Appearance

You can use the following properties to display and customize appearance of ToolbarColorSelector items:

PropertyDescription
ItemCornerRadiusGets or sets the corner radius applied to ToolbarColorSelector colors. This is a bindable property.
ItemHeightGets or sets the height of ToolbarColorSelector items. This is a bindable property.
ItemWidthGets or sets the width of ToolbarColorSelector items. This is a bindable property.

Selection Border Appearance

You can use the following properties to display and customize appearance of ToolbarColorSelector selection border:

PropertyDescription
SelectionBorderColorGets or sets the color of the ToolbarColorSelector ‘s selection border. This is a bindable property.
SelectionBorderThicknessGets or sets the thickness of the selection border within the ToolbarColorSelector. This is a bindable property.
SelectionBorderCornerRadiusGets or sets the corner radius of the selection border within the ToolbarColorSelector. This is a bindable property.
SelectionBorderPaddingGets or sets paddings of the selection border within the ToolbarColorSelector. This is a bindable property.

Customize Animations

The ToolbarColorSelector displays two animations when you select its item:

The first animation changes scale of the tapped item. Use the PressedScale property to specify the scale factor of the tapped item.

The second animation moves the selection border to the selected item.

Use the AnimationDuration property to specify the duration of these animations. The property value is applied to both of these animations.

Implements

INotifyPropertyChanged

IElementController

Inheritance

System.Object BindableObject Element DevExpress.Maui.Core.Internal.DXElementBaseCore DXElementBase ToolbarElementBase ToolbarItemBase ToolbarColorSelector

Extension Methods

Yield<ToolbarColorSelector>()

YieldIfNotNull<ToolbarColorSelector>()

See Also

ToolbarColorSelector Members

Items

DevExpress.Maui.Controls Namespace