nuits.jp blog

C#, Xamarin, WPFを中心に書いています。Microsoft MVP for Development Technologies。

Xamarin.Forms用の汎用Behaviorライブラリをリリースました

Xamarin.Forms用の汎用Behaviorライブラリをリリースました!

www.nuget.org

コード&詳細ドキュメント(まだ下記中ですが)はこちらにあります。

github.com

たとえば、こんな感じでイベント発生時にEventのパスを指定してEventのプロパティを引数にCommandを実行したり

<ListView ItemsSource="{Binding Fruits}">
    <ListView.Behaviors>
        <behaviorsPack:EventToCommandBehavior
            EventName="ItemTapped"
            Command="{Binding SelectedFruitCommand}"
            EventArgsPropertyPath="Item"/>
    </ListView.Behaviors>
public ICommand SelectedFruitCommand => new Command<Fruit>(fruits =>
{
    ...
});

こんな感じで、ボタンクリック時に確認ダイアログを表示してからCommandを実行したり

<Button Text="Show Display Alert">
    <Button.Behaviors>
        <behaviorsPack:DisplayAlertBehavior
            EventName="Clicked"
            Title="Alert Title"
            Message="Please select either."
            Accept="OK"
            AcceptCommand="{Binding AcceptCommand}"
            Cancel="Cancel""/>
    </Button.Behaviors>
</Button>

Behavior作成時の基底クラスもいくつか用意しています。例えば親のBindingContextを継承するInheritBindingBehaviorとか。

色々便利です。多分。

良かったら使っていただけると嬉しいです。
ご要望はぜひIssueへ!