PR Feedback (#2454)
* Correct WebViewCompatible disposal - Ensure code analysis didn't trigger in implementation - IDisposable members also need dtor * Enable GenerateAssemblyInfo * Convert System.Runtime.WindowsRuntime package to local reference * Correct sample namespace
This commit is contained in:
Родитель
a19d8dc01a
Коммит
6b02fdb1bb
|
@ -4,7 +4,6 @@
|
|||
<TargetFramework>net462</TargetFramework>
|
||||
<RootNamespace>Microsoft.Toolkit.Forms.UI.Controls</RootNamespace>
|
||||
<AssemblyName>Microsoft.Toolkit.Forms.UI.Controls</AssemblyName>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
|
||||
<Title>Windows Community Toolkit Windows Forms Controls</Title>
|
||||
|
@ -31,9 +30,9 @@
|
|||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.0.0" />
|
||||
<PackageReference Include="System.Runtime.WindowsRuntime" PrivateAssets="All">
|
||||
<Version>4.0.0</Version>
|
||||
</PackageReference>
|
||||
<Reference Include="System.Runtime.WindowsRuntime">
|
||||
<HintPath>$(WINDIR)\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Microsoft.Toolkit.Sample.Forms.WebView.WebView
|
||||
namespace Microsoft.Toolkit.Sample.Forms.WebView
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ using System.Windows.Forms;
|
|||
using Microsoft.Toolkit.Win32.UI.Controls;
|
||||
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
|
||||
|
||||
namespace Microsoft.Toolkit.Sample.Forms.WebView.WebView
|
||||
namespace Microsoft.Toolkit.Sample.Forms.WebView
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Microsoft.Toolkit.Sample.Forms.WebView.WebView
|
||||
namespace Microsoft.Toolkit.Sample.Forms.WebView
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
<TargetFramework>net462</TargetFramework>
|
||||
<RootNamespace>Microsoft.Toolkit.Wpf.UI.Controls</RootNamespace>
|
||||
<AssemblyName>Microsoft.Toolkit.Wpf.UI.Controls</AssemblyName>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
|
||||
<Title>Windows Community Toolkit WPF Controls</Title>
|
||||
|
@ -66,9 +65,9 @@
|
|||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<PackageReference Include="System.Runtime.WindowsRuntime" PrivateAssets="All">
|
||||
<Version>4.0.0</Version>
|
||||
</PackageReference>
|
||||
<Reference Include="System.Runtime.WindowsRuntime">
|
||||
<HintPath>$(WINDIR)\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -2,30 +2,13 @@
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Windows Community Toolkit Controls for WPF")]
|
||||
[assembly: AssemblyDescription("WPF controls from Windows Community Toolkit")]
|
||||
|
||||
// Make sure this is the same in the VisualToolsManifest.xml file
|
||||
[assembly: AssemblyProduct("Windows Community Toolkit")]
|
||||
[assembly: AssemblyCopyright("\x00a9 Microsoft Corporation. All rights reserved.")]
|
||||
[assembly: AssemblyCompany("Microsoft Corporation")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: NeutralResourcesLanguage("en-US")]
|
||||
#if DEBUG
|
||||
[assembly: AssemblyConfiguration("Debug")]
|
||||
#else
|
||||
[assembly: AssemblyConfiguration("Release")]
|
||||
#endif
|
||||
|
||||
// Dependencies
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ using System.Windows;
|
|||
|
||||
namespace Microsoft.Toolkit.Wpf.UI.Controls
|
||||
{
|
||||
public interface IWebViewCompatibleAdapter : IWebViewCompatible, IDisposable
|
||||
public interface IWebViewCompatibleAdapter : IWebViewCompatible
|
||||
{
|
||||
FrameworkElement View { get; }
|
||||
|
||||
|
|
|
@ -27,14 +27,6 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
|
||||
public abstract FrameworkElement View { get; }
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected internal abstract void Dispose(bool disposing);
|
||||
|
||||
public abstract bool GoBack();
|
||||
|
||||
public abstract bool GoForward();
|
||||
|
@ -62,4 +54,4 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
BindingOperations.SetBinding(this, wpfProperty, binder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,9 +10,9 @@ using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
|
|||
|
||||
namespace Microsoft.Toolkit.Wpf.UI.Controls
|
||||
{
|
||||
internal sealed class WebBrowserCompatibilityAdapter : WebBaseCompatibilityAdapter
|
||||
internal sealed class WebBrowserCompatibilityAdapter : WebBaseCompatibilityAdapter, IDisposable
|
||||
{
|
||||
private WebBrowser _browser = new WebBrowser();
|
||||
private WebBrowser _browser;
|
||||
|
||||
private void OnBrowserNavigated(object sender, NavigationEventArgs e)
|
||||
{
|
||||
|
@ -25,6 +25,11 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
ContentLoading?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
public WebBrowserCompatibilityAdapter()
|
||||
{
|
||||
_browser = new WebBrowser();
|
||||
}
|
||||
|
||||
public override Uri Source
|
||||
{
|
||||
get => _browser?.Source;
|
||||
|
@ -43,6 +48,18 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
|
||||
public override FrameworkElement View => _browser;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~WebBrowserCompatibilityAdapter()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public override event EventHandler<WebViewControlNavigationStartingEventArgs> NavigationStarting;
|
||||
|
||||
public override event EventHandler<WebViewControlContentLoadingEventArgs> ContentLoading;
|
||||
|
@ -93,13 +110,17 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
Bind(nameof(Source), SourceProperty, _browser);
|
||||
}
|
||||
|
||||
protected internal override void Dispose(bool disposing)
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_browser?.Dispose();
|
||||
if (_browser != null)
|
||||
{
|
||||
_browser.Dispose();
|
||||
}
|
||||
|
||||
_browser = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,9 +8,14 @@ using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
|
|||
|
||||
namespace Microsoft.Toolkit.Wpf.UI.Controls
|
||||
{
|
||||
internal sealed class WebViewCompatibilityAdapter : WebBaseCompatibilityAdapter
|
||||
internal sealed class WebViewCompatibilityAdapter : WebBaseCompatibilityAdapter, IDisposable
|
||||
{
|
||||
private WebView _webView = new WebView();
|
||||
private WebView _webView;
|
||||
|
||||
public WebViewCompatibilityAdapter()
|
||||
{
|
||||
_webView = new WebView();
|
||||
}
|
||||
|
||||
public override Uri Source
|
||||
{
|
||||
|
@ -30,6 +35,17 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
|
||||
public override bool CanGoForward => _webView.CanGoForward;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~WebViewCompatibilityAdapter()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public override event EventHandler<WebViewControlNavigationStartingEventArgs> NavigationStarting
|
||||
{
|
||||
add
|
||||
|
@ -94,13 +110,17 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
Bind(nameof(Source), SourceProperty, _webView);
|
||||
}
|
||||
|
||||
protected internal override void Dispose(bool disposing)
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_webView?.Dispose();
|
||||
if (_webView != null)
|
||||
{
|
||||
_webView.Dispose();
|
||||
}
|
||||
|
||||
_webView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -40,6 +40,11 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
BindingOperations.SetBinding(this, SourceProperty, binder);
|
||||
}
|
||||
|
||||
~WebViewCompatible()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public static bool IsLegacy { get; } = !Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Web.UI.Interop.WebViewControl");
|
||||
|
||||
private IWebViewCompatibleAdapter _implementation;
|
||||
|
@ -83,7 +88,10 @@ namespace Microsoft.Toolkit.Wpf.UI.Controls
|
|||
{
|
||||
if (isDisposing)
|
||||
{
|
||||
_implementation.Dispose();
|
||||
if (_implementation is IDisposable disposable)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче