首页 > Windows开发 > 详细

WPF应用程序内嵌网页

时间:2018-09-11 11:10:19      阅读:236      评论:0      收藏:0      [点我收藏+]
原文:WPF应用程序内嵌网页

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/shaynerain/article/details/78160984

WPF内嵌网页,可以将网页本地化,经查找相关资料后,决定采用CefSharp

1、首先新建WPF工程,打开工具进入NUGET,搜索CefSharp,然后安装CefSharp.Wpf

2、完成后,将项目改为x64或者x86,然后添加引用,这里有两种方法分开来说,大同小异

3、方法一:直接在xaml文件中引用,文件如下

<Window x:Class="WpfApplication1.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

        <cefSharp:ChromiumWebBrowser  Name="mychrome" Grid.Row="0" Address="http://blog.csdn.net/shaynerain"/>
    </Grid>
</Window>
4、方法二:在cs文件中添加引用,需要两个文件都做修改

using System.Windows;
using CefSharp.Wpf;

namespace WpfApplication2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        ChromiumWebBrowser webView = null;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string path = "http://blog.csdn.net/shaynerain";

            webView = new ChromiumWebBrowser();
            browserGrid.Children.Add(webView);
            webView.Address = path; 
        }
    }
}
<Window x:Class="WpfApplication2.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication2"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid Name="browserGrid">
        
    </Grid>
</Window>





最后,虽然可以实现功能,但是使用起来,平滑感不友好






WPF应用程序内嵌网页

原文:https://www.cnblogs.com/lonelyxmas/p/9625579.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!