Added minimal example of how CefSharp can be used. Only WPF so far.

This commit is contained in:
Per Lundberg
2013-11-12 13:14:11 +02:00
parent 4c389d8eba
commit 58792baa5e
22 changed files with 846 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<UserControl x:Class="CefSharp.MinimalExample.Wpf.Views.Main.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
d:DesignWidth="640"
d:DesignHeight="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<cefSharp:WebView Grid.Row="0"
Address="http://www.google.com"
WebBrowser="{Binding WebBrowser, Mode=OneWayToSource}"
Title="{Binding Title, Mode=TwoWay}" />
<StatusBar Grid.Row="1">
<ProgressBar HorizontalAlignment="Right"
IsIndeterminate="{Binding WebBrowser.IsLoading}"
Width="100"
Height="16"
Margin="3" />
<Separator />
<!-- TODO: Could show hover link URL here -->
<TextBlock />
</StatusBar>
</Grid>
</UserControl>

View File

@@ -0,0 +1,13 @@
using System.Windows.Controls;
namespace CefSharp.MinimalExample.Wpf.Views.Main
{
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
DataContext = new MainViewModel();
}
}
}

View File

@@ -0,0 +1,39 @@
using CefSharp.MinimalExample.Wpf.Mvvm;
using CefSharp.Wpf;
using System.ComponentModel;
using System.Windows;
namespace CefSharp.MinimalExample.Wpf.Views.Main
{
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;
}
}
}
}