如何刷新 WPF Web 浏览器
How to refresh WPF web browser
我注意到 WebBrowser 元素有一个奇怪的问题。每次更新网站时,在构建应用程序后,我都必须手动右键单击网络浏览器并单击“刷新”才能看到更改后的网站。我怎样才能让它自动刷新?我正在使用空白 WPF 模板。
我试图通过 (NewsInfo.Refresh();) 刷新我的页面,但我只有错误消息:
System.Windows.Markup.XamlParseException
HResult = 0x80131501
Message = Invoking the constructor for type "TubbyLauncher.MainWindow" matching the specified binding constraints caused an exception., Line number 6, position 9.
Source = PresentationFramework
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException (Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load (XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml (XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml (Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo (Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent (Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup ()
at System.Windows.Application. <. ctor> b__1_0 (Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall (Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen (Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl ()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext (Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper (Object obj)
at System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
at System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run (CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke ()
at System.Windows.Threading.Dispatcher.ProcessQueue ()
at System.Windows.Threading.Dispatcher.WndProcHook (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & handled)
at MS.Win32.HwndWrapper.WndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation (Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall (Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen (Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl (DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage (MSG & msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl (DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame (DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run ()
at System.Windows.Application.RunDispatcher (Object ignore)
at System.Windows.Application.RunInternal (Window window)
at System.Windows.Application.Run ()
at TubbyLauncher.App.Main ()
This exception was originally thrown at this call stack:
[External Code]
TubbyLauncher.MainWindow.MainWindow () in MainWindow.xaml.cs
Inner Exception 1:
COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
这是我的代码:
using System;
using System.Collections.Generic;
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.Navigation;
using System.Windows.Shapes;
namespace TubbyLauncher
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
NewsInfo.Refresh();
}
private void Frame_Navigated(object sender, NavigationEventArgs e)
{
}
private void LaunchButton_Click(object sender, RoutedEventArgs e)
{
try
{
Launcher.PlayGame();
}
catch (Exception ex)
{
Launcher.LaunchDiag("Launcher couldn't find game, please reinstall Slendertubbies.", "Game not found!");
}
}
private void Website_Click(object sender, RoutedEventArgs e)
{
Launcher.LaunchWebstie("https://seba0456.itch.io/slendertubbies/");
}
}
}
我的项目:
https://drive.google.com/file/d/1VM8g7ytZhRgnX1JnIFXB70yjslHBNUve/view?usp=sharing
我用过:
var url = "https://www.microsoft.com";
NewsInfo.Navigate(url + "?refreshToken=" + Guid.NewGuid().ToString());
改为:
NewsInfo.Refresh();
我注意到 WebBrowser 元素有一个奇怪的问题。每次更新网站时,在构建应用程序后,我都必须手动右键单击网络浏览器并单击“刷新”才能看到更改后的网站。我怎样才能让它自动刷新?我正在使用空白 WPF 模板。 我试图通过 (NewsInfo.Refresh();) 刷新我的页面,但我只有错误消息:
System.Windows.Markup.XamlParseException
HResult = 0x80131501
Message = Invoking the constructor for type "TubbyLauncher.MainWindow" matching the specified binding constraints caused an exception., Line number 6, position 9.
Source = PresentationFramework
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException (Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load (XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml (XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml (Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo (Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent (Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup ()
at System.Windows.Application. <. ctor> b__1_0 (Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall (Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen (Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl ()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext (Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper (Object obj)
at System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
at System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run (CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke ()
at System.Windows.Threading.Dispatcher.ProcessQueue ()
at System.Windows.Threading.Dispatcher.WndProcHook (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & handled)
at MS.Win32.HwndWrapper.WndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean & handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation (Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall (Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen (Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl (DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc (IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage (MSG & msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl (DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame (DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run ()
at System.Windows.Application.RunDispatcher (Object ignore)
at System.Windows.Application.RunInternal (Window window)
at System.Windows.Application.Run ()
at TubbyLauncher.App.Main ()
This exception was originally thrown at this call stack:
[External Code]
TubbyLauncher.MainWindow.MainWindow () in MainWindow.xaml.cs
Inner Exception 1:
COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
这是我的代码:
using System;
using System.Collections.Generic;
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.Navigation;
using System.Windows.Shapes;
namespace TubbyLauncher
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
NewsInfo.Refresh();
}
private void Frame_Navigated(object sender, NavigationEventArgs e)
{
}
private void LaunchButton_Click(object sender, RoutedEventArgs e)
{
try
{
Launcher.PlayGame();
}
catch (Exception ex)
{
Launcher.LaunchDiag("Launcher couldn't find game, please reinstall Slendertubbies.", "Game not found!");
}
}
private void Website_Click(object sender, RoutedEventArgs e)
{
Launcher.LaunchWebstie("https://seba0456.itch.io/slendertubbies/");
}
}
}
我的项目: https://drive.google.com/file/d/1VM8g7ytZhRgnX1JnIFXB70yjslHBNUve/view?usp=sharing
我用过:
var url = "https://www.microsoft.com";
NewsInfo.Navigate(url + "?refreshToken=" + Guid.NewGuid().ToString());
改为:
NewsInfo.Refresh();