Action Behavior for Livet.
Provides a function to easily call an action class from View (xaml).
MIT-License
https://www.nuget.org/packages/ActionBehavior.Livet/
- Install LivetCask.Mvvm and ActionBehavior.Livet by NuGet.
- Add an action resolver in your project.
using System.ComponentModel.Composition;
using ActionBehavior.Livet;
using Livet;
namespace Hoge
{
[Export(typeof(IActionResolver))]
public class ActionResolver : IActionResolver
{
public string Resolve(ViewModel vm, string action);
{
return $"Hoge.Actions.{action}"
}
}
}
- Add an ViewModel
using Livet;
namespace Hoge
{
public class MainWIndowViewModel : ViewModel
{
}
}
- Add an action class.
using System;
using System.Threading.Tasks;
using Livet;
namespace Hoge
{
public class Hello : ActionCommand<MainWindowViewModel>
{
public override Task<bool> Execute(object sender, EventArgs evnt, object parameter)
{
System.Windows.MessageBox.Show("hello");
return OK;
}
}
}
- Call Excute on view (xaml)
<Window
・・・(略)・・・
xmlns:ab="clr-namespace:ActionBehavior.Livet;assembly=ActionBehavior.Livet"
>
<Window.DataContext>
<vm:MainWindowViewModel/>
</Window.DataContext>
<Button Content="Hello">
<i:Interactions.Triggers>
<i:EventTrigger EventName="Click">
<ab:Execute Action="Hello" />
</i:EventTrigger>
</i:Interactions.Triggers>
</Button>