wpf vue cef 交互

<UserControl x:Class="LabInOnePC.View.UcSampleBankView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:cef="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
             mc:Ignorable="d" Height="900" Width="1100">
    <Grid Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="48"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Button Cursor="Hand" Width="42" Height="42" BorderThickness="0" VerticalAlignment="Top" 
                    HorizontalAlignment="Right" x:Name="btnClose">
            <Button.Background>
                <ImageBrush ImageSource="/Images/PC/Close1.png"/>
            </Button.Background>
        </Button>
        <cef:ChromiumWebBrowser x:Name="webBrowser" Grid.Row="1"/>
        <Grid VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="gdLoad" Grid.Row="1">
            <StackPanel>
                <Image Source="/Images/PC/LoadingData.png" Width="{StaticResource LoadingImageWidth}" Height="{StaticResource LoadingImageHeight}"></Image>
                <TextBlock Margin="0,14,0,0" Text="加载中…" Foreground="#666666" FontSize="{StaticResource FontSize12}" HorizontalAlignment="Center"></TextBlock>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl> 

页面xmal.cs

public partial class UcSampleBankView : UserControl
    {
        public UcSampleBankView()
        {
            InitializeComponent();

            CefSharpSettings.LegacyJavascriptBindingEnabled = true;
            CefSharpSettings.ConcurrentTaskExecution = true;

            string address =ConfigurationManager.AppSettings["SampleBank"] + "?token=" + ViewModel.Global.CurrentUser.token;   //"http://localhost:8080/" + "?token=" + ViewModel.Global.CurrentUser.token;
            webBrowser.Address = address;

            webBrowser.LoadError += _webView_LoadError;

            webBrowser.FrameLoadEnd += (sender, e) =>
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    gdLoad.Visibility = System.Windows.Visibility.Collapsed;
                });
                this.Dispatcher.Invoke(new Action(delegate
                {
                    webBrowser.WebBrowser.ExecuteScriptAsyncWhenPageLoaded(@"(async function() {await CefSharp.BindObjectAsync('callbackObj', 'bound');})();");
                }));
            };
            webBrowser.MenuHandler = new MenuHandler();

            ////注册js对象据说,79版本以上的注册方法是下面这句
            webBrowser.JavascriptObjectRepository.Register("bound", new FormMainProcess(this), false);

            btnClose.Click += (sender, e) =>
            {
                this.ResultData?.Invoke(false);
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    xxx.Close();
                });
                OnClose();
            };
        }

        public void OnClose()
        {
            try
            {
                webBrowser.CloseDevTools();
                webBrowser.GetBrowser().CloseBrowser(true);
            }
            catch { }

            try
            {
                if (webBrowser != null)
                {
                    webBrowser.Dispose();
                }
            }
            catch { }
        }

        public void _webView_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
        {
            MessageBox.Show("加载页面失败,请退出客户端进行重试");
            webBrowser.Dispose();
        }
    }


   vue传过来数据进行处理

[ComVisible(true)]
    public class FormMainProcess : IResultObject
    {
        UserControl control;
        public Action<object> ResultData { get; set; }
        public FormMainProcess(UserControl user)
        {
            control = user;
        }


        public void speakMsg(string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                var result = false;
                ViewModel vm = new ViewModel();
                if (proId != null)
                {
                    var resultList = JsonConvert.DeserializeObject<List<VoModel>>(message);
                    vm.List = resultList;

                    result = vm.xxx();
                }
   

                if (result)
                {
                    var view = control as UcSampleBankView;
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        view.OnClose();
                        view.ResultData?.Invoke(result);
                        ControlManager.Close();
                    });
                }
            }
        }
    }


   

 /// <summary>
    /// cef菜单事件
    /// </summary>
    public class MenuHandler : CefSharp.IContextMenuHandler
    {

        void CefSharp.IContextMenuHandler.OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model)
        {
            model.Clear();
        }

        bool CefSharp.IContextMenuHandler.OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags)
        {
            //throw new NotImplementedException();
            return false;
        }

        void CefSharp.IContextMenuHandler.OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame)
        {
            //throw new NotImplementedException();
        }

        bool CefSharp.IContextMenuHandler.RunContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model, CefSharp.IRunContextMenuCallback callback)
        {
            return false;
        }
    }
   

 定义交互模型

 public class SimpleModel
    {
        public long? pageNum { get; set; }
        public long? id { get; set; }
        public long? categoryId { get; set; }
        public string name { get; set; }
        public string amount { get; set; }
        public string no { get; set; }
    }

vue

window.bound.speakMsg(JSON.stringify(this.selectMap));
console.log(JSON.stringify(this.selectMap));

相关推荐

wpf .netcore 导出pdf文件

【代码】wpf .netcore 导出pdf文件。

somethingGoWay的专栏 380

wpf .netcore 导出docx文件

下载nuget包 DocX。

somethingGoWay的专栏 251

wpf .netcore6.0 导出html文件

【代码】wpf .netcore6.0 导出html文件。

somethingGoWay的专栏 138

wpf SerialPortStream 循环串口进行连接仪器

【代码】wpf SerialPortStream 循环串口进行连接仪器。

somethingGoWay的专栏 174

wpf 多个RadioButton公用一个样式,每个显示的图片不一样

【代码】wpf 多个RadioButton公用一个样式,每个显示的图片不一样。

somethingGoWay的专栏 157

wpf 只能输入基数的文本框

【代码】wpf 只能输入基数的文本框。

somethingGoWay的专栏 137

wpf 只能输入int类型的文本框

我做的这个文本框,可设置最大值,最小值,有失去焦点事件的话,失去焦点文本框里的数字是你上次填的数字,避免数据为空的情况。

somethingGoWay的专栏 369

wpf 自定义控件,只能输入小数点,并且能控制小数点位数

调用:DecimalCount就是小数点位数,一般不去设置,最多三位小数点。如果失去焦点,当前的数据会时你上次输入的数据,这样不会出现数据为空的情况。

somethingGoWay的专栏 338

wpf 自定义密码文本框,并且可以双向绑定

【代码】wpf 自定义密码文本框,并且可以双向绑定。

somethingGoWay的专栏 309

wpf 自定义输入ip地址的文本框

PS:因为是上位机,所以文本框里面写了键盘,如果不需要可删除。

somethingGoWay的专栏 311

sqlite dapper 数据量过大,增加索引,写成公用方法。

PS:数据库中索引名称是不能重复的,所以先判断索引是否存在,存在则不会创建索引。

somethingGoWay的专栏 152

Sqlit Dapper根据模型新建表

这样模型中也可写表不用的字段,用来数据绑定等其他用途。还可以做成公用方法便于调用和利用。PS:如果模型中有不需要加到数据库中的字段则加标记。

somethingGoWay的专栏 264

Sqlite 改变已有表中的字段名称

【代码】Sqlite 改变已有表中的字段名称。

somethingGoWay的专栏 249

Sqlite 数据库和表已经建成,投入使用,再在表中增加字段

【代码】sqllite 数据库和表已经建成,投入使用,再在表中增加字段。

somethingGoWay的专栏 289

wpf ListBox中所有文本框回车跳到下个文本框.

我的ListBox有十行三列的文本框,回车会跳到下一个,一列到底回车跳到下一列,到最后一个又会跳到第一个.并且跳到文本框文本框中的文字会被全部选中.代码如下.xmal.cs 这里也可以ListBox的Loaded事件,就不用给ListBox取名字了.暂时还不知这两种有什么区别,哪种更好一点.我用的Mvvm框架.

somethingGoWay的专栏 356

【转】微软教学:三种方法屏蔽Win7/Win8.1升级Win10推送

经 过上述修改,Win7/Win8.1用户的Win10升级通知和升级功能就全部关闭了,不想使用这种方法升级的用户,或者不想被通知打扰的用户可以按照这 些方法操作。用户免费升级到了Win10,不过也有一批用户在升级和使用过程中遇到了严重问题,因而回退到了原来的系统,另外还有一部分用户对新系统还在评估之中,暂时不打算升级。此后,升级Win10的推送功能被关闭,如果用户想升级Win10,需要依靠手动更新,或者再次在组策略开启升级推送功能。,点击“确定”即可(若已关闭升级功能,该项目默认为0)

somethingGoWay的专栏 5万+

wpf .net core6.0 图片打印预览,可以拖拽位置,滚轮放大缩小,打印

接上一篇生成二维码

somethingGoWay的专栏 369

wpf .net core6.0 生成二维码

这是打印预览按钮所在页面。

somethingGoWay的专栏 453

wpf oxyplot 双向绑定 刷新局部数据

首先,声明,我用的是CommunityToolkit.Mvvm框架,大家可以根据自己的实际情况来改。我是根据combobox的选择,来更新plotview的数据。页面plotview双向绑定是这样的。我是初始化页面的时候初始化控件。

somethingGoWay的专栏 835

wpf win8系统popup位置会跑偏

在App.xmal.cs里调用也行,在初始化页面的时候调用也可以.修改弹出菜单相对于相应菜单项是左对齐还是右对齐。

somethingGoWay的专栏 292

wpf Textbox绑定非string类型,经常出现红框

Textbox绑定非string类型,为空会出现红框.失去焦点也会出现红框.用下面方法就不会出现红框,也不会出现xaml绑定错误了.

somethingGoWay的专栏 460

下位机用命令来连接wifi(包括查询wifi,连接wifi,断开wifi,查询wifi状态等)

TextBlock x:Name="NoWlanTextBlock" Grid.Row="1" Text="貌似没有无线网卡" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Red" Visibility="{Binding NoWlan}"/>Content="取消" Background="LightGray" Foreground="Black" Click="BtnClose_Click" />

somethingGoWay的专栏 284

C# log日志

还有LogUtil.Log(ex.Message);

somethingGoWay的专栏 503

C# 更改入站规则,增加端口信息

重点在于c:/Windows/Systm32/FirewallAPI.dll,要将这个dll复制并引用到自己的项目中。//创建firewall管理类的实例。//加入到防火墙的管理策略。/// 将应用程序添加到防火墙例外。//加入到防火墙的管理策略。/// 应用程序可执行文件全路径。/// 删除防火墙例外中应用程序。/// 协议(TCP、UDP)//程序的路径及文件名。/// 协议(TCP、UDP)/// 添加防火墙例外端口。/// 删除防火墙例外端口。/// 程序的绝对路径。/// 应用程序名称。

somethingGoWay的专栏 562

oxyplot 点击x,y交汇的点,标签一直显示

/GetPlot()是自定义方法。

somethingGoWay的专栏 819

wpf oxyPlot 峰值画线标注

/将线添加到图标的容器中。//将线添加到图标的容器中。IsZoomEnabled = false,//坐标轴缩放关闭。IsPanEnabled = false,//图表缩放功能关闭。IsZoomEnabled = false,//坐标轴缩放关闭。IsPanEnabled = false,//图表缩放功能关闭。

somethingGoWay的专栏 935

C# wpf 修改windows时间设置(有网络和无网络都可)

需要设置的时间返回网络时间

somethingGoWay的专栏 1005

wpf 在程序里关机(关闭电脑)

需要的小伙伴最好写个判断,是否要关机之类的,点击是或者确认才关掉。

somethingGoWay的专栏 477

开机自启动-秒开

2.计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 的Userinit,把启动路径放进去。1.打开注册表 运行窗口 regedit。

somethingGoWay的专栏 169

WPF TextBlock加下划线 并且与字段有间距

如果你不需要设置下划线与字段之间的距离,并且要在后台处理。PenOffset就是设置下划线与字段的距离。如果你不需要设置下划线与字段之间的距离。

somethingGoWay的专栏 1371
上一篇: WPF Cef JS交互
下一篇: 查找ListBox里面ListBoxItem
SomethingGoWay
SomethingGoWay 麟角科技 麟角科技
博客等级 码龄15年 18粉丝 54原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值