mirror of https://github.com/cefsharp/CefSharp.git

committed by
Alex Maitland

7 changed files with 71 additions and 24 deletions
-
16CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj
-
1CefSharp.Wpf.Example/CefSharp.Wpf.Example.netcore.csproj
-
1CefSharp.Wpf.Example/Controls/ChromiumWebBrowserWithScreenshotSupport.cs
-
3CefSharp.Wpf.Example/Handlers/MenuHandler.cs
-
55CefSharp.Wpf.Example/RelayCommand.cs
-
17CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs
-
2CefSharp.Wpf.Example/packages.config
@ -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)))) |
|||
{ |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue