Skip to content

Commit abd2b9b

Browse files
Merge pull request #45 from MicrosoftEdge/usr/jasteph/reorgSample
Usr/jasteph/reorg sample
2 parents 4746e20 + 2881023 commit abd2b9b

File tree

130 files changed

+188
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+188
-10
lines changed

GettingStartedGuide/.gitignore renamed to GettingStartedGuides/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ ARM64/
44
x64/
55
.vs/
66
packages/
7+
8+
obj/
9+
bin/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="WPFSample.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:WPFSample"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace WPFSample
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Window x:Class="WPFSample.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:WPFSample"
7+
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="800">
10+
11+
<DockPanel>
12+
13+
<DockPanel DockPanel.Dock="Top">
14+
<Button x:Name="ButtonGo"
15+
DockPanel.Dock="Right"
16+
Click="ButtonGo_Click"
17+
Content="Go"
18+
/>
19+
<TextBox Name="addressBar"/>
20+
</DockPanel>
21+
22+
<wv2:WebView2 Name="webView"
23+
Source="https://www.microsoft.com"
24+
/>
25+
</DockPanel>
26+
27+
</Window>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
using Microsoft.Web.WebView2.Core;
16+
17+
18+
namespace WPFSample
19+
{
20+
/// <summary>
21+
/// Interaction logic for MainWindow.xaml
22+
/// </summary>
23+
public partial class MainWindow : Window
24+
{
25+
public MainWindow()
26+
{
27+
InitializeComponent();
28+
webView.NavigationStarting += EnsureHttps;
29+
InitializeAsync();
30+
31+
}
32+
33+
async void InitializeAsync()
34+
{
35+
await webView.EnsureCoreWebView2Async(null);
36+
webView.CoreWebView2.WebMessageReceived += UpdateAddressBar;
37+
38+
await webView.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.chrome.webview.postMessage(window.document.URL);");
39+
await webView.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.chrome.webview.addEventListener(\'message\', event => alert(event.data));");
40+
41+
}
42+
43+
void UpdateAddressBar(object sender, CoreWebView2WebMessageReceivedEventArgs args)
44+
{
45+
String uri = args.TryGetWebMessageAsString();
46+
addressBar.Text = uri;
47+
webView.CoreWebView2.PostWebMessageAsString(uri);
48+
}
49+
50+
void EnsureHttps(object sender, CoreWebView2NavigationStartingEventArgs args)
51+
{
52+
String uri = args.Uri;
53+
if (!uri.StartsWith("https://"))
54+
{
55+
webView.CoreWebView2.ExecuteScriptAsync($"alert('{uri} is not safe, try an https link')");
56+
args.Cancel = true;
57+
}
58+
}
59+
60+
private void ButtonGo_Click(object sender, RoutedEventArgs e)
61+
{
62+
if (webView != null && webView.CoreWebView2 != null)
63+
{
64+
webView.CoreWebView2.Navigate(addressBar.Text);
65+
}
66+
}
67+
68+
}
69+
70+
}
71+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<UseWPF>true</UseWPF>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Web.WebView2" Version="0.9.538-prerelease" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30204.135
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFSample", "WPFSample.csproj", "{7F520883-A7EE-4834-BE8D-DF7293B4A2A9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{7F520883-A7EE-4834-BE8D-DF7293B4A2A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7F520883-A7EE-4834-BE8D-DF7293B4A2A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7F520883-A7EE-4834-BE8D-DF7293B4A2A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7F520883-A7EE-4834-BE8D-DF7293B4A2A9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {78497C18-B95E-4A20-AB81-FE52C352D981}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)