From 09b92eac8083c1e3a39ed252c694334f33d0e9e9 Mon Sep 17 00:00:00 2001 From: amaitland Date: Wed, 13 Jan 2016 10:53:46 +1000 Subject: [PATCH] For simplicities sake strip out all the MVVM parts and simplify the example down to the bare minimum (Code is declared in the MainWindow now) --- CefSharp.MinimalExample.Wpf/App.xaml | 3 +- .../Binding/TitleConverter.cs | 20 ++++++++ .../CefSharp.MinimalExample.Wpf.csproj | 11 +---- CefSharp.MinimalExample.Wpf/MainWindow.xaml | 24 ++++++++-- .../Mvvm/PropertyChangedExtensionMethods.cs | 48 ------------------- .../ViewModels/MainViewModel.cs | 39 --------------- .../Views/MainView.xaml | 30 ------------ .../Views/MainView.xaml.cs | 14 ------ 8 files changed, 45 insertions(+), 144 deletions(-) create mode 100644 CefSharp.MinimalExample.Wpf/Binding/TitleConverter.cs delete mode 100644 CefSharp.MinimalExample.Wpf/Mvvm/PropertyChangedExtensionMethods.cs delete mode 100644 CefSharp.MinimalExample.Wpf/ViewModels/MainViewModel.cs delete mode 100644 CefSharp.MinimalExample.Wpf/Views/MainView.xaml delete mode 100644 CefSharp.MinimalExample.Wpf/Views/MainView.xaml.cs diff --git a/CefSharp.MinimalExample.Wpf/App.xaml b/CefSharp.MinimalExample.Wpf/App.xaml index 6e3da63..78e9486 100644 --- a/CefSharp.MinimalExample.Wpf/App.xaml +++ b/CefSharp.MinimalExample.Wpf/App.xaml @@ -1,8 +1,9 @@  - + diff --git a/CefSharp.MinimalExample.Wpf/Binding/TitleConverter.cs b/CefSharp.MinimalExample.Wpf/Binding/TitleConverter.cs new file mode 100644 index 0000000..145bce5 --- /dev/null +++ b/CefSharp.MinimalExample.Wpf/Binding/TitleConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace CefSharp.MinimalExample.Wpf.Binding +{ + public class TitleConverter : IValueConverter + { + object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + + return "CefSharp.MinimalExample.Wpf - " + (value ?? "No Title Specified"); + } + + object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return System.Windows.Data.Binding.DoNothing; + } + } +} diff --git a/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj b/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj index 3d38304..6e5b30b 100644 --- a/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj +++ b/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj @@ -78,10 +78,6 @@ MSBuild:Compile Designer - - MainView.xaml - - MSBuild:Compile Designer @@ -90,17 +86,13 @@ App.xaml Code + MainWindow.xaml Code - - MSBuild:Compile - Designer - - Code @@ -131,6 +123,7 @@ + diff --git a/CefSharp.MinimalExample.Wpf/MainWindow.xaml b/CefSharp.MinimalExample.Wpf/MainWindow.xaml index a02a076..ecbd777 100644 --- a/CefSharp.MinimalExample.Wpf/MainWindow.xaml +++ b/CefSharp.MinimalExample.Wpf/MainWindow.xaml @@ -1,8 +1,26 @@  - + + + + + + + + + + + + + diff --git a/CefSharp.MinimalExample.Wpf/Mvvm/PropertyChangedExtensionMethods.cs b/CefSharp.MinimalExample.Wpf/Mvvm/PropertyChangedExtensionMethods.cs deleted file mode 100644 index 5a3285c..0000000 --- a/CefSharp.MinimalExample.Wpf/Mvvm/PropertyChangedExtensionMethods.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq.Expressions; - -namespace CefSharp.MinimalExample.Wpf.Mvvm -{ - public static class PropertyChangedExtensionMethods - { - // Based on http://www.wpftutorial.net/INotifyPropertyChanged.html - public static bool ChangeAndNotify(this PropertyChangedEventHandler handler, - ref T field, T value, Expression> memberExpression) - { - if (memberExpression == null) - { - throw new ArgumentNullException("memberExpression"); - } - - var body = memberExpression.Body as MemberExpression; - if (body == null) - { - throw new ArgumentException("Lambda must return a property."); - } - - if (EqualityComparer.Default.Equals(field, value)) - { - return false; - } - - field = value; - - var vmExpression = body.Expression as ConstantExpression; - if (vmExpression != null) - { - var lambda = Expression.Lambda(vmExpression); - var vmFunc = lambda.Compile(); - var sender = vmFunc.DynamicInvoke(); - - if (handler != null) - { - handler(sender, new PropertyChangedEventArgs(body.Member.Name)); - } - } - - return true; - } - } -} diff --git a/CefSharp.MinimalExample.Wpf/ViewModels/MainViewModel.cs b/CefSharp.MinimalExample.Wpf/ViewModels/MainViewModel.cs deleted file mode 100644 index 74e99cd..0000000 --- a/CefSharp.MinimalExample.Wpf/ViewModels/MainViewModel.cs +++ /dev/null @@ -1,39 +0,0 @@ -using CefSharp.MinimalExample.Wpf.Mvvm; -using CefSharp.Wpf; -using System.ComponentModel; -using System.Windows; - -namespace CefSharp.MinimalExample.Wpf.ViewModels -{ - public class MainViewModel - { - public event PropertyChangedEventHandler PropertyChanged; - - private IWpfWebBrowser webBrowser; - public IWpfWebBrowser WebBrowser - { - get { return webBrowser; } - set { PropertyChanged.ChangeAndNotify(ref webBrowser, value, () => WebBrowser); } - } - - private string title; - public string Title - { - get { return title; } - set { PropertyChanged.ChangeAndNotify(ref title, value, () => Title); } - } - - public MainViewModel() - { - PropertyChanged += OnPropertyChanged; - } - - private void OnPropertyChanged(object sender, PropertyChangedEventArgs e) - { - if (e.PropertyName == "Title") - { - Application.Current.MainWindow.Title = "CefSharp.MinimalExample.Wpf - " + Title; - } - } - } -} diff --git a/CefSharp.MinimalExample.Wpf/Views/MainView.xaml b/CefSharp.MinimalExample.Wpf/Views/MainView.xaml deleted file mode 100644 index 5971357..0000000 --- a/CefSharp.MinimalExample.Wpf/Views/MainView.xaml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/CefSharp.MinimalExample.Wpf/Views/MainView.xaml.cs b/CefSharp.MinimalExample.Wpf/Views/MainView.xaml.cs deleted file mode 100644 index 2881ad1..0000000 --- a/CefSharp.MinimalExample.Wpf/Views/MainView.xaml.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Windows.Controls; -using CefSharp.MinimalExample.Wpf.ViewModels; - -namespace CefSharp.MinimalExample.Wpf.Views -{ - public partial class MainView : UserControl - { - public MainView() - { - InitializeComponent(); - DataContext = new MainViewModel(); - } - } -}