弹出控件上的超链接找不到超链接文件

如何解决弹出控件上的超链接找不到超链接文件

出于某种原因,hyperlink 控件上的以下 popup 无法打开 google 网站。弹出窗口正确显示了链接,但是当我单击链接时,出现以下错误。如果我直接在浏览器上使用,所使用的链接 (https://www.google.com/) 可以正常工作。我在这里可能缺少什么,我们可以让它发挥作用吗?

错误

enter image description here

MainWindow.xaml

.....
 <Grid>
        <TextBlock TextWrapping="Wrap">text <Run TextDecorations="Underline" MouseEnter="run_MouseEnter">link</Run>
        </TextBlock>
        <Popup Name="popLink" StaysOpen="False" Placement="Mouse" MaxWidth="200" PopupAnimation="Slide" AllowsTransparency = "True">
            <Border BorderBrush="Beige" BorderThickness="2" Background="White">
                <TextBlock Margin="10" TextWrapping="Wrap"> <Hyperlink Click="Hyperlink_Click" NavigateUri="https://www.google.com/">More info</Hyperlink>
                </TextBlock>
        </Border>
    </Popup>
</Grid>

MainWindow.xaml.cs

private void run_MouseEnter(object sender,MouseEventArgs e)
{
    popLink.IsOpen = true;
}

private void Hyperlink_Click(object sender,RoutedEventArgs e)
{
    System.Diagnostics.Process.Start(((Hyperlink)sender).NavigateUri.ToString());
}

更新

有关错误的更多详细信息:

enter image description here

System.ComponentModel.Win32Exception
  HResult=0x80004005
  Message=The system cannot find the file specified.
  Source=System.Diagnostics.Process
  StackTrace:
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName)
   at WpfApp2.MainWindow.Hyperlink_Click(Object sender,RoutedEventArgs e) in C:\DotNET_Gen\WPF_Core\WpfApp2\MainWindow.xaml.cs:line 45
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source,RoutedEventArgs args,Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args)
   at System.Windows.ContentElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.Documents.Hyperlink.OnClick()
   at System.Windows.Documents.Hyperlink.DispatchNavigation(Object sender)
   at System.Windows.Documents.Hyperlink.OnMouseLeftButtonUp(Object sender,MouseButtonEventArgs e)
   at System.Windows.Documents.Hyperlink.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender,MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler,Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler,Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source,Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender,RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender,RoutedEventArgs args)
   at System.Windows.ContentElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd,InputMode mode,Int32 timestamp,RawMouseActions actions,Int32 x,Int32 y,Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd,WindowMessage msg,IntPtr wParam,IntPtr lParam,Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd,Int32 msg,Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,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,Int32 numArgs,Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority,TimeSpan timeout,Delegate method,Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,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 WpfApp2.App.Main()

解决方法

事实证明,问题实际上与应用无法找到默认浏览器的位置有关(在我的情况下为 Chrome)。我通过阅读以下帖子发现了问题的原因:

俗话说:Give credit where credit is due。因此,功劳归于以下用户:

  1. Felipe Oriani 在他的 this 帖子中:如果您的应用无法找到浏览器的路径该怎么办
  2. Ahmad Hindash 在他关于如何查找浏览器位置的 this 帖子中
  3. Dxiv on details on 为什么有时您可能会收到上述错误。

根据我对上述帖子的阅读,我能够解决以下问题:

private void Hyperlink_Click(object sender,RoutedEventArgs e)
{
   //PLEASE NOTE: You would want to programmatically find the location of you browser as user `Felipe Oriani` did in his above mentioned post. For brevity,I am leaving that part.
   System.Diagnostics.Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",((Hyperlink)sender).NavigateUri.ToString());
}

注意:目前,我不会将我的回复标记为答案,因为其他用户可能会提出更好的解决方案(在这种情况下,我会将他/她的回复标记为答案) .

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-