Back to Devexpress

ToolbarToggleButton Class

maui-devexpress-dot-maui-dot-controls-4a3038ad.md

latest26.8 KB
Original Source

ToolbarToggleButton Class

A button within a DXToolbar that has two states: checked and unchecked. You can group several ToolbarToggleButtons to implement exclusive selection.

Namespace : DevExpress.Maui.Controls

Assembly : DevExpress.Maui.Controls.dll

NuGet Package : DevExpress.Maui.Controls

Declaration

csharp
[DXLicenseMAUI]
public class ToolbarToggleButton :
    ToolbarButton,
    DXCheckGroupConnector.IDXCheckGroupConnectorOwner

Remarks

Add ToolbarToggleButton to DXToolbar

The following code sample displays a ToolbarToggleButton within the DXToolbar control:

xaml
<ContentPage ...
    xmlns:dxc="clr-namespace:DevExpress.Maui.Controls;assembly=DevExpress.Maui.Controls">
    <Grid>
        <dxc:DXToolbar>
            <!-- ... -->
            <dxc:ToolbarToggleButton Content="Bookmark" Icon="bookmark"/>
        </dxc:DXToolbar>
    </Grid>
</ContentPage>

Group ToggleToolbarButtons

You can group several ToolbarToggleButtons to implement exclusive selection. In this case, selecting one ToolbarToggleButton deselects other ToolbarToggleButton in this group.

Specify the same GroupName property value for all ToolbarToggleButtons within the group. The following code sample displays the Layout group of ToolbarToggleButton with exclusive selection:

xaml
<ContentPage ...
    xmlns:dxc="clr-namespace:DevExpress.Maui.Controls;assembly=DevExpress.Maui.Controls">
    <Grid>
        <dxc:DXToolbar>
            <!-- ... -->
            <dxc:ToolbarToggleButton x:Name="OnePage" GroupName="Layout" Icon="onepage" IsChecked="true" />
            <dxc:ToolbarToggleButton x:Name="TitlePage" GroupName="Layout" Icon="titlepage" />
            <dxc:ToolbarToggleButton x:Name="TwoPages" GroupName="Layout" Icon="twopages"/>
        </dxc:DXToolbar>
    </Grid>
</ContentPage>

Use the AllowUncheckInGroup to specify whether ToolbarToggleButtons within a group can be unchecked.

Handle Taps and Check Items

You can use the following events to handle a ToolbarToggleButton tap:

EventDescription
IsCheckedGets or sets whether the ToolbarToggleButton is checked. This is a bindable property.
ToolbarButton.ClickedFires when a user taps the toolbar button.
CheckedChangingFires before the ToolbarToggleButton.IsChecked property is changed.
CheckedChangedFires after the ToolbarToggleButton.IsChecked property is changed.

When the item is checked, you can use the Checked*Color properties to customize the colors of button elements (text, background, icon, and more).

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

xaml
<ContentPage ...
    xmlns:dxc="clr-namespace:DevExpress.Maui.Controls;assembly=DevExpress.Maui.Controls">
    <Grid>
        <dxc:DXToolbar>
            <!-- ... -->
            <dxc:DXToolbar>
                <dxc:ToolbarToggleButton x:Name="bookmarkbutton" Content="Bookmark" Icon="bookmark" Command="{Binding TapButtonCommand}"
                                            CommandParameter="{Binding ButtonType, Source={x:Reference bookmarkbutton}}"/>
            </dxc:DXToolbar>
        </dxc:DXToolbar>
    </Grid>
</ContentPage>

You can customize button appearance in pressed state. Use Pressed*Color properties to specify colors for various button elements (text, background, icon, and more).

Button Types

The ToolbarToggleButton class includes the ButtonType property. The list below contains the available button types and corresponding button appearances in different states:

ToolButton (default)

StateImage
Default
Pressed
Checked
CheckedPressed
Disabled
CheckedDisabled

Accent

StateImage
Default
Pressed
Checked
CheckedPressed
Disabled
CheckedDisabled

Filled

StateImage
Default
Pressed
Checked
CheckedPressed
Disabled
CheckedDisabled

Outlined

StateImage
Default
Pressed
Checked
CheckedPressed
Disabled
CheckedDisabled

Text

StateImage
Default
Pressed
Checked
CheckedPressed
Disabled
CheckedDisabled

Button Availability

Use the IsEnabled property to specify whether the ToolbarToggleButton is enabled. You can customize button appearance in disabled state. Use the Disabled*Color property to change the colors of button elements (text, background, icon, and more).

Handle Loading

You can use the following inherited member to handle the ToolbarToggleButton 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 ToolbarToggleButton appearance settings:

PropertyDescription
ThemeSeedColorGets or sets the predefined color used to generate colors for ToolbarButton. This is a bindable property.
CornerRadiusGets or sets a ToolbarContentItemBase descendant’s corner radius. This is a bindable property.
MarginGets or sets the margin value of a ToolbarContentItemBase descendant. This is a bindable property.
PaddingGets or sets the padding of a ToolbarContentItemBase descendant. This is a bindable property.
ShowContentGets or sets whether a ToolbarContentItemBase descendant’s content is displayed. This is a bindable property.
ContentGets or sets the custom content of the toolbar button. This is a bindable property.
ContentTemplateGets or sets a template that configures the content‘s appearance. This is a bindable property.
ViewStyleGets or sets the style of the DXToggleButton control within the ToolbarToggleButton. This is a bindable property.
StyleGets or sets the style applied to a DXElementBase descendant. This is a bindable property.

Size and Alignment

You can use the following properties to customize common ToolbarToggleButton size and alignment settings:

PropertyDescription
HeightRequestGets or sets height of a ToolbarContentItemBase descendant. This is a bindable property.
MaximumHeightRequestGets or sets maximum height of a ToolbarContentItemBase descendant. This is a bindable property.
MinimumHeightRequestGets or sets minimum height of a ToolbarContentItemBase descendant. This is a bindable property.
WidthRequestGets or sets width of a ToolbarContentItemBase descendant. This is a bindable property.
MaximumWidthRequestGets or sets maximum width of a ToolbarContentItemBase descendant. This is a bindable property.
MinimumWidthRequestGets or sets minimum width of a ToolbarContentItemBase descendant. This is a bindable property.
HorizontalOptionsGets or sets the horizontal alignment of a ToolbarContentItemBase descendant. This is a bindable property.
HorizontalContentAlignmentGets or sets the horizontal alignment of a ToolbarContentItemBase descendant’s content. This is a bindable property.
VerticalOptionsGets or sets the vertical alignment of a ToolbarContentItemBase descendant. This is a bindable property.
VerticalContentAlignmentGets or sets the vertical alignment of a ToolbarContentItemBase descendant’s content. This is a bindable property.

Background Color

You can use the following properties to change the background color for a ToolbarToggleButton :

PropertyDescription
BackgroundColorGets or sets a ToolbarContentItemBase descendant’s background color. This is a bindable property.
DisabledBackgroundColorGets or sets the background color of the ToolbarButton when it is disabled. This is a bindable property.
PressedBackgroundColorGets or sets the background color of the ToolbarButton when it is pressed. This is a bindable property.
CheckedBackgroundColorGets or sets the background color of the ToolbarToggleButton when it is checked. This is a bindable property.
CheckedPressedBackgroundColorGets or sets the background color of the ToolbarToggleButton when it is checked and pressed. This is a bindable property.
CheckedDisabledBackgroundColorGets or sets the background color of the ToolbarToggleButton when it is checked and disabled. This is a bindable property.

Border

You can use the following properties to customize the border for a ToolbarToggleButton :

PropertyDescription
BorderColorGets or sets a ToolbarContentItemBase descendant’s border color. This is a bindable property.
BorderThicknessGets or sets a ToolbarContentItemBase descendant’s border thickness. This is a bindable property.
PressedBorderColorGets or sets the border color of the ToolbarButton when it is pressed. This is a bindable property.
DisabledBorderColorGets or sets the border color of a ToolbarButton when it is disabled. This is a bindable property.
CheckedBorderColorGets or sets the border color of the ToolbarToggleButton when it is checked. This is a bindable property.
CheckedPressedBorderColorGets or sets the border color of the ToolbarToggleButton when it is checked and pressed. This is a bindable property.
CheckedDisabledBorderColorGets or sets the border color of the ToolbarToggleButton when it is checked and disabled. This is a bindable property.

Icon

You can use the following properties to display and customize an icon within a ToolbarToggleButton :

PropertyDescription
IconGets or sets the icon that is displayed within a ToolbarContentItemBase descendant. This is a bindable property.
ShowIconGets or sets whether a ToolbarContentItemBase descendant’s icon is displayed. This is a bindable property.
IconAspectGets or sets the aspect of the icon that is displayed within a ToolbarContentItemBase descendant. This is a bindable property.
IconHeightGets or sets the icon height of a ToolbarContentItemBase descendant. This is a bindable property.
IconWidthGets or sets the icon width of a ToolbarContentItemBase descendant. This is a bindable property.
IconPlacementGets or sets the icon placement within a ToolbarContentItemBase descendant. This is a bindable property.
IconIndentGets or sets the icon indent of a ToolbarContentItemBase descendant. This is a bindable property.
IconColorizationEnabledGets or sets whether the toolbar item’s icon should change its colors in pressed and disabled states. This is a bindable property.
IconColorGets or sets the icon color of a ToolbarContentItemBase descendant. This is a bindable property.
DisabledIconColorGets or sets the icon color of the ToolbarButton when it is disabled. This is a bindable property.
PressedIconColorGets or sets the icon color of the ToolbarButton when it is pressed. This is a bindable property.
CheckedIconColorGets or sets the icon color of the ToolbarToggleButton when it is checked. This is a bindable property.
CheckedDisabledIconColorGets or sets the icon color of the ToolbarToggleButton when it is checked and disabled. This is a bindable property.
CheckedPressedIconColorGets or sets the icon color of the ToolbarToggleButton when it is checked and pressed. This is a bindable property.

Text and Font Settings

You can use the following properties to display and customize font settings for a ToolbarToggleButton :

PropertyDescription
FontAttributesGets or sets a ToolbarContentItemBase descendant’s font attributes. This is a bindable property.
FontFamilyGets or sets a ToolbarContentItemBase descendant’s font family. This is a bindable property.
FontSizeGets or sets a ToolbarContentItemBase descendant’s font size. This is a bindable property.
FontAutoScalingEnabledGets or sets whether the toolbar item’s text is scaled according to the operating system’s text scale setting. This is a bindable property.
TextColorGets or sets the text color of a ToolbarContentItemBase descendant. This is a bindable property.
DisabledTextColorGets or sets the text color of the ToolbarButton when it is disabled. This is a bindable property.
PressedTextColorGets or sets the text color of the ToolbarButton when it is pressed. This is a bindable property.
CheckedTextColorGets or sets the text color of the ToolbarToggleButton when it is checked. This is a bindable property.
CheckedPressedTextColorGets or sets the text color of the ToolbarToggleButton when it is checked and pressed. This is a bindable property.
CheckedDisabledTextColorGets or sets the text color of the ToolbarToggleButton when it is checked and disabled. This is a bindable property.
TextCharacterSpacingGets or sets the spacing between characters of a ToolbarContentItemBase descendant’s text. This is a bindable property.
TextDecorationsGets or sets text decorations applied to a ToolbarContentItemBase descendant’s text. This is a bindable property.
TextHorizontalAlignmentGets or sets the horizontal alignment applied to a ToolbarContentItemBase descendant’s text. This is a bindable property.
TextVerticalAlignmentGets or sets the vertical alignment applied to a ToolbarContentItemBase descendant’s text. This is a bindable property.
TextLineBreakModeGets or sets the line breaking mode for a ToolbarContentItemBase descendant’s text. This is a bindable property.
TextLineHeightGets or sets line height applied to a ToolbarContentItemBase descendant’s text. This is a bindable property.
TextMaxLinesGets or sets the maximum number of a ToolbarContentItemBase descendant’s text. This is a bindable property.

Customize Animation

The ToolbarToggleButton displays the animation when you tap it. You can use the following properties to customize this animation:

PropertyDescription
PressedScaleGets or sets the toolbar button scale when it is pressed. This is a bindable property.
AnimationDurationGets or sets the duration of the ToolbarButton ‘s scale animation. This is a bindable property.

Implements

INotifyPropertyChanged

IElementController

Inheritance

System.Object BindableObject Element DevExpress.Maui.Core.Internal.DXElementBaseCore DXElementBase ToolbarElementBase ToolbarItemBase ToolbarContentItemBase ToolbarButton ToolbarToggleButton

Extension Methods

Yield<ToolbarToggleButton>()

YieldIfNotNull<ToolbarToggleButton>()

See Also

ToolbarToggleButton Members

Items

DevExpress.Maui.Controls Namespace