diff --git a/README.md b/README.md index c6d4722..fc65948 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ The idea is that I want to use this repository as a lookup when facing different * [StringToSolidBrushConverter](xaml.experiences/resources/converters/stringsolidbrushconverter) * Commands * [DelegateCommand](xaml.experiences/resources/commands/delegatecommand) + * [AsyncCommand](xaml.experiences/resources/commands/asynccommand) * Helpers * [Observing objects](xaml.experiences/resources/helpers/observingobjects) diff --git a/xaml.experiences/resources/commands/asynccommand/App.config b/xaml.experiences/resources/commands/asynccommand/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/xaml.experiences/resources/commands/asynccommand/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/xaml.experiences/resources/commands/asynccommand/App.xaml b/xaml.experiences/resources/commands/asynccommand/App.xaml new file mode 100644 index 0000000..4541c5b --- /dev/null +++ b/xaml.experiences/resources/commands/asynccommand/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/xaml.experiences/resources/commands/asynccommand/App.xaml.cs b/xaml.experiences/resources/commands/asynccommand/App.xaml.cs new file mode 100644 index 0000000..7ce3fa5 --- /dev/null +++ b/xaml.experiences/resources/commands/asynccommand/App.xaml.cs @@ -0,0 +1,9 @@ +namespace asynccommand +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App + { + } +} \ No newline at end of file diff --git a/xaml.experiences/resources/commands/asynccommand/MainViewModel.cs b/xaml.experiences/resources/commands/asynccommand/MainViewModel.cs new file mode 100644 index 0000000..0ffafaa --- /dev/null +++ b/xaml.experiences/resources/commands/asynccommand/MainViewModel.cs @@ -0,0 +1,44 @@ +using System.Threading.Tasks; +using System.Windows.Input; +using asynccommand.Resources; +using asynccommand.Resources.Commands; +using observingobjects; + +namespace asynccommand +{ + public class MainViewModel : BaseViewModel + { + private bool m_isBusy; + private string m_text; + + public MainViewModel() + { + ChangeTextAsyncCommand = new AsyncCommand(ChangeTextAsync); + } + + public ICommand ChangeTextAsyncCommand { get; } + + public string Text + { + get => m_text; + set => SetProperty(ref m_text, value); + } + + public bool IsBusy + { + get => m_isBusy; + set => SetProperty(ref m_isBusy, value); + } + + private async Task ChangeTextAsync(object newText) + { + if (newText is string stringinput) + { + IsBusy = true; + await Task.Delay(4200); + Text = stringinput; + IsBusy = false; + } + } + } +} \ No newline at end of file diff --git a/xaml.experiences/resources/commands/asynccommand/MainWindow.xaml b/xaml.experiences/resources/commands/asynccommand/MainWindow.xaml new file mode 100644 index 0000000..5f5d69d --- /dev/null +++ b/xaml.experiences/resources/commands/asynccommand/MainWindow.xaml @@ -0,0 +1,40 @@ + + + + + + + +