Files
cefsharp/CefSharp.Wpf/Internals/DelegateCommand.cs
Alex Maitland f43cd64c55 Import CefSharp.Wpf.HwndHost into main repository. (#4981)
* HwndHost - Initial import

* HwndHost - Add Example to solution and use common IWpfChromiumWebBrowser interface

* HwndHost - Update UpdateNugetPackages.ps1

* HwndHost - Add Nuspec

* HwndHost Example - Upgrade version

* HwndHost Example - Try non self contained build for debug and release

* Test - Add basic HwndHost tests

Probably need to revisit these, little bit hacky creating the window

* HwndHost - Allow any RequestContext that inherits from Core.RequestContext

Cheery pick of https://github.com/cefsharp/CefSharp.Wpf.HwndHost/pull/31

* HwndHost Example - Disable arm64

Example will be removed shortly, so it doesn't matter too much now.
It will be moved to MinimalExample and the Wpf Example expanded

* HwndHost - Delete delegate command

* Upgrade packages

* Nuget - Move Nuspec file to PackageReference folder

---------

Co-authored-by: amaitland <307872+amaitland@users.noreply.github.com>
2025-01-18 06:40:48 +10:00

71 lines
2.4 KiB
C#

// Copyright © 2013 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
using System.Windows.Input;
namespace CefSharp.Wpf.Internals
{
/// <summary>
/// DelegateCommand
/// </summary>
/// <seealso cref="ICommand" />
internal class DelegateCommand : ICommand
{
/// <summary>
/// The command handler
/// </summary>
private readonly Action commandHandler;
/// <summary>
/// The can execute handler
/// </summary>
private readonly Func<bool> canExecuteHandler;
/// <summary>
/// Occurs when changes occur that affect whether or not the command should execute.
/// </summary>
public event EventHandler CanExecuteChanged;
/// <summary>
/// Initializes a new instance of the <see cref="DelegateCommand"/> class.
/// </summary>
/// <param name="commandHandler">The command handler.</param>
/// <param name="canExecuteHandler">The can execute handler.</param>
public DelegateCommand(Action commandHandler, Func<bool> canExecuteHandler = null)
{
this.commandHandler = commandHandler;
this.canExecuteHandler = canExecuteHandler;
}
/// <summary>
/// Defines the method to be called when the command is invoked.
/// </summary>
/// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to null.</param>
public void Execute(object parameter)
{
commandHandler();
}
/// <summary>
/// Defines the method that determines whether the command can execute in its current state.
/// </summary>
/// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to null.</param>
/// <returns>true if this command can be executed; otherwise, false.</returns>
public bool CanExecute(object parameter)
{
return
canExecuteHandler == null ||
canExecuteHandler();
}
/// <summary>
/// Raises the can execute changed.
/// </summary>
public void RaiseCanExecuteChanged()
{
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
}
}