forked from cefsharp/CefSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves cefsharp#1307
- Loading branch information
Showing
8 changed files
with
231 additions
and
85 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,19 @@ | ||
<Window | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="CefSharp.Wpf.Example.SpawnBrowsersWindow" | ||
Title="TestWindow" Height="594" Width="651"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="150"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
<ListBox x:Name="itemList" Margin="10,42,10,10" IsSynchronizedWithCurrentItem="False" SelectionChanged="ListBox_SelectionChanged" /> | ||
<ContentControl x:Name="browserContainer" Content="Browser goes here" Grid.Column="1" Margin="10,42,10,10"/> | ||
<Button Content="Test" x:Name="btnTest" Height="27" Margin="10,10,10,0" VerticalAlignment="Top" Click="Button_Click"/> | ||
<Label Content="Speed" Grid.Column="1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/> | ||
<Label x:Name="speedLabel" Content="0" Grid.Column="1" HorizontalAlignment="Left" Margin="300,10,0,0" VerticalAlignment="Top"/> | ||
<Slider x:Name="speedSlider" Grid.Column="1" HorizontalAlignment="Left" Margin="58,15,0,0" VerticalAlignment="Top" Width="237" Maximum="1" Value="0.01" Minimum="0.01" ValueChanged="speedSlider_ValueChanged"/> | ||
|
||
</Grid> | ||
</Window> |
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,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Shapes; | ||
|
||
namespace CefSharp.Wpf.Example | ||
{ | ||
/// <summary> | ||
/// Interaction logic for TestWindow.xaml | ||
/// </summary> | ||
public partial class SpawnBrowsersWindow : Window | ||
{ | ||
bool _isRunning; | ||
bool _requestCancel; | ||
private const int MAX_SPEED = 1000; | ||
|
||
public SpawnBrowsersWindow() | ||
{ | ||
InitializeComponent(); | ||
for (int i = 1; i <= 100; i++) | ||
{ | ||
itemList.Items.Add("Item " + i); | ||
} | ||
} | ||
|
||
private async void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
if (browserContainer.Content is ChromiumWebBrowser) | ||
{ | ||
ChromiumWebBrowser oldBrowser = browserContainer.Content as ChromiumWebBrowser; | ||
browserContainer.Content = null; | ||
oldBrowser.Dispose(); | ||
} | ||
await Task.Delay(10); | ||
|
||
ChromiumWebBrowser browser = new ChromiumWebBrowser() | ||
{ | ||
Address = "http://www.google.com" | ||
}; | ||
browserContainer.Content = browser; | ||
//browser.ExecuteScriptAsync("document.body.innerHTML = '';"); | ||
} | ||
|
||
private async void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
if (_isRunning) | ||
{ | ||
StartStopTest(false); | ||
} | ||
else | ||
{ | ||
StartStopTest(true); | ||
|
||
for (int i = 0; i < itemList.Items.Count; i++) | ||
{ | ||
itemList.SelectedIndex = i; | ||
await Task.Delay((int)(MAX_SPEED * speedSlider.Value)); | ||
if (_requestCancel) | ||
break; | ||
} | ||
|
||
StartStopTest(false); | ||
} | ||
} | ||
|
||
private void StartStopTest(bool isStart) | ||
{ | ||
_requestCancel = !isStart; | ||
_isRunning = isStart; | ||
btnTest.Content = isStart ? "Cancel" : "Test"; | ||
itemList.IsEnabled = !_isRunning; | ||
} | ||
|
||
private void speedSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) | ||
{ | ||
speedLabel.Content = string.Format("{0}ms", (int)(MAX_SPEED * speedSlider.Value)); | ||
} | ||
} | ||
} |
Oops, something went wrong.