-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright © 2017 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.Example | ||
{ | ||
public class RelayCommand : ICommand | ||
{ | ||
private readonly Action<object> commandHandler; | ||
private readonly Func<object, bool> canExecuteHandler; | ||
|
||
public event EventHandler CanExecuteChanged; | ||
|
||
public RelayCommand(Action<object> commandHandler, Func<object, bool> canExecuteHandler = null) | ||
{ | ||
this.commandHandler = commandHandler; | ||
this.canExecuteHandler = canExecuteHandler; | ||
} | ||
public RelayCommand(Action commandHandler, Func<bool> canExecuteHandler = null) | ||
: this(_ => commandHandler(), canExecuteHandler == null ? null : new Func<object, bool>(_ => canExecuteHandler())) | ||
{ | ||
} | ||
|
||
public void Execute(object parameter) | ||
{ | ||
commandHandler(parameter); | ||
} | ||
|
||
public bool CanExecute(object parameter) | ||
{ | ||
return | ||
canExecuteHandler == null || | ||
canExecuteHandler(parameter); | ||
} | ||
|
||
public void RaiseCanExecuteChanged() | ||
{ | ||
if (CanExecuteChanged != null) | ||
{ | ||
CanExecuteChanged(this, EventArgs.Empty); | ||
} | ||
} | ||
} | ||
|
||
public class RelayCommand<T> : RelayCommand | ||
{ | ||
public RelayCommand(Action<T> commandHandler, Func<T, bool> canExecuteHandler = null) | ||
: base(o => commandHandler(o is T t ? t : default(T)), canExecuteHandler == null ? null : new Func<object, bool>(o => canExecuteHandler(o is T t ? t : default(T)))) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters