Skip to content

Commit

Permalink
Wpf.Example - Remove MvvmLight
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau authored and amaitland committed Nov 9, 2020
1 parent 95716da commit 8ad0c76
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 24 deletions.
16 changes: 1 addition & 15 deletions CefSharp.Wpf.Example/CefSharp.Wpf.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,12 @@
<StartupObject>CefSharp.Wpf.Example.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonServiceLocator, Version=2.0.2.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.4.1.0, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
Expand All @@ -121,6 +106,7 @@
<Compile Include="JavascriptCallbackMainWindow.xaml.cs">
<DependentUpon>JavascriptCallbackMainWindow.xaml</DependentUpon>
</Compile>
<Compile Include="RelayCommand.cs" />
<Compile Include="StandardTabControlWindow.xaml.cs">
<DependentUpon>StandardTabControlWindow.xaml</DependentUpon>
</Compile>
Expand Down
1 change: 0 additions & 1 deletion CefSharp.Wpf.Example/CefSharp.Wpf.Example.netcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<ProjectReference Include="..\CefSharp.Example\CefSharp.Example.netcore.csproj" />
<ProjectReference Include="..\CefSharp.Wpf\CefSharp.Wpf.netcore.csproj" />
<ProjectReference Include="..\CefSharp\CefSharp.netcore.csproj" />
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
<PackageReference Include="cef.redist.x86" Version="87.1.1" />
<PackageReference Include="cef.redist.x64" Version="87.1.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GalaSoft.MvvmLight.Command;
using Size = System.Windows.Size;

namespace CefSharp.Wpf.Example.Controls
Expand Down
3 changes: 1 addition & 2 deletions CefSharp.Wpf.Example/Handlers/MenuHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using GalaSoft.MvvmLight.Command;

namespace CefSharp.Wpf.Example.Handlers
{
Expand Down Expand Up @@ -199,7 +198,7 @@ bool IContextMenuHandler.RunContextMenu(IWebBrowser chromiumWebBrowser, IBrowser
break;
}
}
}, keepTargetAlive: true)
})
});
}
webBrowser.ContextMenu = menu;
Expand Down
55 changes: 55 additions & 0 deletions CefSharp.Wpf.Example/RelayCommand.cs
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))))
{
}
}
}
17 changes: 14 additions & 3 deletions CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using CefSharp.Example;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace CefSharp.Wpf.Example.ViewModels
{
public class BrowserTabViewModel : ViewModelBase
public class BrowserTabViewModel : INotifyPropertyChanged
{
private string address;
public string Address
Expand Down Expand Up @@ -93,6 +92,9 @@ public DownloadItem DownloadItem
}

private bool legacyBindingEnabled;

public event PropertyChangedEventHandler PropertyChanged;

public bool LegacyBindingEnabled
{
get { return legacyBindingEnabled; }
Expand Down Expand Up @@ -228,5 +230,14 @@ public void LoadCustomRequestExample()

WebBrowser.LoadUrlWithPostData("https://cefsharp.com/PostDataTest.html", postData);
}

protected void Set<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
field = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
2 changes: 0 additions & 2 deletions CefSharp.Wpf.Example/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
<packages>
<package id="cef.redist.x64" version="87.1.1" targetFramework="net472" />
<package id="cef.redist.x86" version="87.1.1" targetFramework="net472" />
<package id="CommonServiceLocator" version="2.0.2" targetFramework="net462" requireReinstallation="true" />
<package id="Microsoft.Net.Compilers" version="2.9.0" targetFramework="net462" developmentDependency="true" />
<package id="MvvmLightLibs" version="5.4.1.1" targetFramework="net462" />
</packages>

0 comments on commit 8ad0c76

Please sign in to comment.