diff --git a/PacticeSolution/CommandSample/App.xaml b/PacticeSolution/CommandSample/App.xaml new file mode 100644 index 0000000..bbc6767 --- /dev/null +++ b/PacticeSolution/CommandSample/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/PacticeSolution/CommandSample/App.xaml.cs b/PacticeSolution/CommandSample/App.xaml.cs new file mode 100644 index 0000000..dbf1fec --- /dev/null +++ b/PacticeSolution/CommandSample/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace CommandSample +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/PacticeSolution/CommandSample/AssemblyInfo.cs b/PacticeSolution/CommandSample/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/PacticeSolution/CommandSample/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/PacticeSolution/CommandSample/CommandSample.csproj b/PacticeSolution/CommandSample/CommandSample.csproj new file mode 100644 index 0000000..4106cb0 --- /dev/null +++ b/PacticeSolution/CommandSample/CommandSample.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net6.0-windows + enable + true + + + diff --git a/PacticeSolution/CommandSample/Commands/MessageCommand.cs b/PacticeSolution/CommandSample/Commands/MessageCommand.cs new file mode 100644 index 0000000..0f67457 --- /dev/null +++ b/PacticeSolution/CommandSample/Commands/MessageCommand.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace CommandSample.Commands +{ + internal class MessageCommand : ICommand + { + private Action _execute; + private Predicate _canExecute; + + public event EventHandler? CanExecuteChanged + { + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } + } + + public MessageCommand(Action execute, Predicate canExecute) + { + _execute = execute; + _canExecute = canExecute; + } + + public bool CanExecute(object? parameter) + { + bool result = _canExecute.Invoke(parameter as string); + return result; + } + + public void Execute(object? parameter) + { + if (_execute == null) + return; + + _execute.Invoke(parameter as string); + } + } +} diff --git a/PacticeSolution/CommandSample/MainWindow.xaml b/PacticeSolution/CommandSample/MainWindow.xaml new file mode 100644 index 0000000..27a4d62 --- /dev/null +++ b/PacticeSolution/CommandSample/MainWindow.xaml @@ -0,0 +1,20 @@ + + + + + + + +