Xamarin.Forms用の汎用Behaviorライブラリをリリースました!
コード&詳細ドキュメント(まだ下記中ですが)はこちらにあります。
たとえば、こんな感じでイベント発生時に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へ!