-
Notifications
You must be signed in to change notification settings - Fork 517
Expand file tree
/
Copy pathMainWindow.xaml
More file actions
144 lines (142 loc) · 13.4 KB
/
MainWindow.xaml
File metadata and controls
144 lines (142 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!--
Copyright (C) Microsoft Corporation. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<Window x:Class="WebView2WpfBrowser.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
xmlns:local="clr-namespace:WebView2WpfBrowser"
x:Name="MyWindow"
Title="MainWindow"
Height="450"
Width="800"
>
<Window.Resources>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.New" Executed="NewCmdExecuted"/>
<CommandBinding Command="ApplicationCommands.Close" Executed="CloseCmdExecuted"/>
<CommandBinding Command="NavigationCommands.BrowseBack" Executed="BackCmdExecuted" CanExecute="BackCmdCanExecute"/>
<CommandBinding Command="NavigationCommands.BrowseForward" Executed="ForwardCmdExecuted" CanExecute="ForwardCmdCanExecute"/>
<CommandBinding Command="NavigationCommands.Refresh" Executed="RefreshCmdExecuted" CanExecute="RefreshCmdCanExecute"/>
<CommandBinding Command="NavigationCommands.BrowseStop" Executed="BrowseStopCmdExecuted" CanExecute="BrowseStopCmdCanExecute"/>
<CommandBinding Command="NavigationCommands.GoToPage" Executed="GoToPageCmdExecuted" CanExecute="GoToPageCmdCanExecute"/>
<CommandBinding Command="NavigationCommands.IncreaseZoom" Executed="IncreaseZoomCmdExecuted" CanExecute="WebViewRequiringCmdsCanExecute"/>
<CommandBinding Command="NavigationCommands.DecreaseZoom" Executed="DecreaseZoomCmdExecuted" CanExecute="DecreaseZoomCmdCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.InjectScriptCommand}" Executed="InjectScriptCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.InjectScriptIFrameCommand}" Executed="InjectScriptIFrameCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.SetUserAgentCommand}" Executed="SetUserAgentCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.GetCookiesCommand}" Executed="GetCookiesCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.DOMContentLoadedCommand}" Executed="DOMContentLoadedCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.NavigateWithWebResourceRequestCommand}" Executed="NavigateWithWebResourceRequestCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.AddOrUpdateCookieCommand}" Executed="AddOrUpdateCookieCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.DeleteCookiesCommand}" Executed="DeleteCookiesCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.DeleteAllCookiesCommand}" Executed="DeleteAllCookiesCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.CustomContextMenuCommand}" Executed="CustomContextMenuCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.PasswordAutosaveCommand}" Executed="PasswordAutosaveCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.GeneralAutofillCommand}" Executed="GeneralAutofillCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.NewBrowserVersionCommand}" Executed="NewBrowserVersionCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.SwipeNavigationCommand}" Executed="SwipeNavigationCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.PdfToolbarSaveCommand}" Executed="PdfToolbarSaveCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.CreateDownloadsButtonCommand}" Executed="CreateDownloadsButtonCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.ToggleMuteStateCommand}" Executed="ToggleMuteStateCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.PrintToPdfCommand}" Executed="PrintToPdfCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.PinchZoomCommand}" Executed="PinchZoomCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.CustomClientCertificateSelectionCommand}" Executed="CustomClientCertificateSelectionCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.DeferredCustomCertificateDialogCommand}" Executed="DeferredCustomCertificateDialogCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.DownloadStartingCommand}" Executed="DownloadStartingCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.BackgroundColorCommand}" Executed="BackgroundColorCmdExecuted" CanExecute="WebViewRequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.SuspendCommand}" Executed="SuspendCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.ResumeCommand}" Executed="ResumeCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
<CommandBinding Command="{x:Static local:MainWindow.CheckUpdateCommand}" Executed="CheckUpdateCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
</Window.CommandBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_New Window" Command="ApplicationCommands.New"/>
<MenuItem Header="_Close" Command="ApplicationCommands.Close"/>
<MenuItem Header="_Inject Script..." Command="{x:Static local:MainWindow.InjectScriptCommand}"/>
<MenuItem Header="_Inject Script Into IFrame..." Command="{x:Static local:MainWindow.InjectScriptIFrameCommand}"/>
<MenuItem Header="_Print to PDF">
<MenuItem Header="Portrait" Command="{x:Static local:MainWindow.PrintToPdfCommand}" CommandParameter="Portrait"/>
<MenuItem Header="Landscape" Command="{x:Static local:MainWindow.PrintToPdfCommand}" CommandParameter="Landscape"/>
</MenuItem>
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="_Increase Zoom" Command="NavigationCommands.IncreaseZoom"/>
<MenuItem Header="_Decrease Zoom" Command="NavigationCommands.DecreaseZoom"/>
<MenuItem Header="_BackgroundColor">
<MenuItem Header="White" Command="{x:Static local:MainWindow.BackgroundColorCommand}" CommandParameter="White"/>
<MenuItem Header="Red" Command="{x:Static local:MainWindow.BackgroundColorCommand}" CommandParameter="Red"/>
<MenuItem Header="Blue" Command="{x:Static local:MainWindow.BackgroundColorCommand}" CommandParameter="Blue"/>
<MenuItem Header="Transparent" Command="{x:Static local:MainWindow.BackgroundColorCommand}" CommandParameter="Transparent"/>
</MenuItem>
<MenuItem Header="_Create Downloads Button" Command="{x:Static local:MainWindow.CreateDownloadsButtonCommand}"/>
</MenuItem>
<MenuItem Header="S_ettings">
<MenuItem Header="WebView _userAgent" Command="{x:Static local:MainWindow.SetUserAgentCommand}"/>
<MenuItem Header="Password _autosave enabled" Name="passwordAutosaveEnabled" IsCheckable="True" IsChecked="False" Command="{x:Static local:MainWindow.PasswordAutosaveCommand}"/>
<MenuItem Header="General _autofill enabled" Name ="generalAutofillEnabled" IsCheckable="True" IsChecked="True" Command="{x:Static local:MainWindow.GeneralAutofillCommand}"/>
<MenuItem Header="Disable Pinch Zoom" Command="{x:Static local:MainWindow.PinchZoomCommand}"/>
<MenuItem Header="Disable Swipe to Navigate" Command="{x:Static local:MainWindow.SwipeNavigationCommand}"/>
<MenuItem Header="Toggle PDF toolbar save button" Command="{x:Static local:MainWindow.PdfToolbarSaveCommand}"/>
<MenuItem Header="WebView _muted" IsCheckable="True" IsChecked="False" Command="{x:Static local:MainWindow.ToggleMuteStateCommand}"/>
</MenuItem>
<MenuItem Header="S_cenario">
<MenuItem Header="Suspend" Command="{x:Static local:MainWindow.SuspendCommand}"/>
<MenuItem Header="Resume" Command="{x:Static local:MainWindow.ResumeCommand}"/>
<MenuItem Header="Check Update" Command="{x:Static local:MainWindow.CheckUpdateCommand}"/>
<MenuItem Header="_DOM Content Loaded" Command="{x:Static local:MainWindow.DOMContentLoadedCommand}"/>
<MenuItem Header="_NavigateWithWebResourceRequest" Command="{x:Static local:MainWindow.NavigateWithWebResourceRequestCommand}"/>
<MenuItem x:Name="newVersionMenuItem" Header="New Browser _Version" Command="{x:Static local:MainWindow.NewBrowserVersionCommand}"/>
<MenuItem Header="_Client Certificate Requested">
<MenuItem Header="_Custom Client Certificate Selection" Command="{x:Static local:MainWindow.CustomClientCertificateSelectionCommand}"/>
<MenuItem Header="_Deferred Custom Client Certificate Selection Dialog" Command="{x:Static local:MainWindow.DeferredCustomCertificateDialogCommand}"/>
</MenuItem>
<MenuItem Header="_Custom Context Menu" Command="{x:Static local:MainWindow.CustomContextMenuCommand}"/>
<MenuItem Header="D_ownload Starting">
<MenuItem Header="_Start Deferred Download" Command="{x:Static local:MainWindow.DownloadStartingCommand}"/>
</MenuItem>
<MenuItem Header="_Cookie Management">
<MenuItem Header="_Get Cookies" Command="{x:Static local:MainWindow.GetCookiesCommand}"/>
<MenuItem Header="_Add Or Update Cookie" Command="{x:Static local:MainWindow.AddOrUpdateCookieCommand}"/>
<MenuItem Header="_Delete Cookie" Command="{x:Static local:MainWindow.DeleteCookiesCommand}"/>
<MenuItem Header="D_elete All Cookies" Command="{x:Static local:MainWindow.DeleteAllCookiesCommand}"/>
</MenuItem>
<MenuItem Header="Intercept _Response" IsCheckable="True" IsChecked="{Binding ElementName=MyWindow, Path=ShowNextWebResponse, Mode=TwoWay}"/>
</MenuItem>
</Menu>
<DockPanel Name="dockPanel" DockPanel.Dock="Top">
<Button DockPanel.Dock="Left" Command="NavigationCommands.BrowseBack">Back</Button>
<Button DockPanel.Dock="Left" Command="NavigationCommands.BrowseForward">Forward</Button>
<Button DockPanel.Dock="Left" Command="NavigationCommands.Refresh">Refresh</Button>
<Button DockPanel.Dock="Left" Command="NavigationCommands.BrowseStop">Stop</Button>
<Button DockPanel.Dock="Right" Command="NavigationCommands.GoToPage" CommandParameter="{Binding ElementName=url,Path=Text}">Go</Button>
<!-- We want the address bar to update based on the WebView's Source, but we don't want the WebView to navigate just from the user typing into the address bar. Therefore we use the OneWay binding mode. -->
<TextBox x:Name="url" Text="{Binding ElementName=webView,Path=Source,Mode=OneWay}">
<TextBox.InputBindings>
<KeyBinding Key="Return" Command="NavigationCommands.GoToPage" CommandParameter="{Binding ElementName=url,Path=Text}" />
</TextBox.InputBindings>
</TextBox>
</DockPanel>
<Grid x:Name="Layout">
<Grid.Background>
<ImageBrush ImageSource="/assets/EdgeWebView2-80.jpg"></ImageBrush>
</Grid.Background>
<!-- If you want to use a specific version of WebView2 Runtime change EvergreenWebView2CreationProperties
to BYOWebView2CreationProperties and follow the steps in MainWindow.xaml
-->
<wv2:WebView2
x:Name="webView"
CreationProperties="{StaticResource EvergreenWebView2CreationProperties}"
Source="https://www.bing.com/"
/>
<!-- The control event handlers are set in code behind so they can be reused when replacing the control after
a WebView2 Runtime's browser process failure
-->
</Grid>
</DockPanel>
</Window>