Code Monkey home page Code Monkey logo

maui.statebutton's Introduction

๐Ÿ“ This is a MAUI version of my Xamarin NuGet

Maui.StateButton Nuget Nuget

License: MIT FOSSA Status Codacy Badge

With this control you are able to create any style of button. This is possible as it acts as a wrapper to your XAML and provides you the events/ commands and properties to bind too.

It's also 100% accessible with each platform seeing/ treating the control as a native button.

Check out the examples, for a bunch of different designs -

Example gif

How to use it?

Install the NuGet package into your shared project project

Install-Package IeuanWalker.Maui.StateButton

Then in the MauiProgram.cs, and the StateButton configuration method -

using IeuanWalker.Maui.StateButton;
builder
	.UseMauiApp<App>()
	.UseStateButton();

What can I do with it?

Properties

Property What it does Extra info
State This changes based on the button state. i.e. Pressed, NotPressed Default state is NotPressed

The binding mode is OneWayToSource so it can only be controlled via this control.

Events

Event What it does
Clicked Triggerd when the button is pressed and released
Pressed Triggerd when the button is pressed. Not triggered when using screenreader or keyboard navigation
Released Triggerd when the button is released. Not triggered when using screenreader or keyboard navigation

Commands

Command What it does
ClickedCommand Triggerd when the button is pressed and released
PressedCommand Triggerd when the button is pressed. Not triggered when using screenreader or keyboard navigation
ReleasedCommand Triggerd when the button is released. Not triggered when using screenreader or keyboard navigation

How to style the button for different states

Simply add a Trigger to any element and bind it to the State property of the button -

<stateButton:StateButton Padding="20,10" BackgroundColor="Red">
    <stateButton:StateButton.StrokeShape>
        <RoundRectangle CornerRadius="10" />
    </stateButton:StateButton.StrokeShape>
    <stateButton:StateButton.Triggers>
        <Trigger TargetType="stateButton:StateButton" Property="State" Value="Pressed">
            <Setter Property="BackgroundColor" Value="Green" />
        </Trigger>
    </stateButton:StateButton.Triggers>

    <Label Text="Test" TextColor="White">
        <Label.Triggers>
            <DataTrigger Binding="{Binding Source={RelativeSource AncestorType={x:Type stateButton:StateButton}}, Path=State}"
                        TargetType="Label"
                        Value="Pressed">
                <Setter Property="TextColor" Value="Blue" />
            </DataTrigger>
        </Label.Triggers>
    </Label>
</stateButton:StateButton>

More examples can be found in the demo app - https://github.com/IeuanWalker/Maui.StateButton/tree/master/Demo/Controls/Examples

Accessibility

The control itself is seen as a native button on both platforms, so inherits the same accessbility attributes. So from a screenreader and keyboard POV it is a native button.

There are a few things you can do to improve the accessibility -

  1. Set the SemanticProperties.Description property on the button. Android is smart enough, that if you dont set this property it will try and find a label within the control to read the text from, iOS does not do this, so if you dont set this property, iOS screenreader will just announce that there is a button, but no name or context is given.

  2. Optionally you can also set the SemanticProperties.Hint property. Using this property you can give more context to what the button is for/ will do.

For example, setting the SemanticProperties.Description to 'Reload', and SemanticProperties.Hint to 'Reload list of contacts'. The user using a screen reader will here something like - 'Reload button, Reload list of contacts, double tap to activate'

Recomended usage

I recommend creating a ControlTemplate so you can easily re-use the control. You can see how i do this in the Example6 example button (xaml/ c#)

License

FOSSA Status

maui.statebutton's People

Contributors

ieuanwalker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

maui.statebutton's Issues

Style's property is not working

Hi,
thanks for your great work.

When we apply backgroundcolor and Stroke from style, button stay transparent and no border are drawn.

    <ContentPage.Resources>
        <ResourceDictionary>
            <Style x:Key="borderButton" TargetType="sb:StateButton" >
                <Setter Property="Stroke" Value="{StaticResource Color2}"></Setter>
                <Setter Property="StrokeThickness" Value="1"></Setter>
                <Setter Property="BackgroundColor" Value="{StaticResource Color3}"></Setter>
                <Setter Property="StrokeShape" Value="RoundRectangle 11,11,11,11"></Setter>
            </Style>
        </ResourceDictionary>
    </ContentPage.Resources>
<sb:StateButton Grid.Row="1" Grid.Column="1"  Style="{DynamicResource borderButton}"  >
                <sb:StateButton.Triggers>
                    <Trigger TargetType="sb:StateButton" Property="State" Value="Pressed">
                        <Setter Property="BackgroundColor" Value="Green" />
                    </Trigger>
                </sb:StateButton.Triggers>
                <VerticalStackLayout Padding="21,8,21,8">
                    <Image  Source="icon_stat.png" Margin="10"></Image>
                    <Label  VerticalOptions="Center"  Text="Baisser &#10; le volume" Style="{StaticResource menuCenterLabel}"/>
                </VerticalStackLayout>
            </sb:StateButton>

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.