WPF 使用ChromiumWebBrowser 嵌套一个JSP的页面之后,页面总是闪烁,有没有人有类似问题,或知道解决办法

303554142 2015-12-02 09:52:47

//WebViewHelper类
using CefSharp;
using CefSharp.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YaMiClient
{
public class WebViewHelper
{
private static ChromiumWebBrowser webBrowser;
private static object _lock = new object();
private WebViewHelper()
{

}

public static void SetInit()
{
if (Cef.IsInitialized)
return;
Cef.Initialize(new CefSettings() { PersistSessionCookies = true});
}

public static void SetDispose()
{
Cef.Shutdown();
}

public static ChromiumWebBrowser GetWebBrowser()
{
if(webBrowser==null)
{
lock(_lock)
{
if(webBrowser==null)
{
webBrowser = new ChromiumWebBrowser();
}
}
}
return webBrowser;
}

public static void SetAddress(string address)
{
if (webBrowser == null)
GetWebBrowser();
webBrowser.Address = address;
}
public static void SetCookies(string url, string domain, Dictionary<string, string> cookies, DateTime dateTime)
{
Cef.GetGlobalCookieManager().SetStoragePath(Environment.CurrentDirectory, true);
cookies.ToList().ForEach(c =>
{
Cookie cookie = new Cookie();
cookie.Creation = DateTime.Now;
cookie.Domain ="";
cookie.Name = c.Key;
cookie.Value = c.Value;
cookie.Expires = dateTime;
Task<bool> task = Cef.GetGlobalCookieManager().SetCookieAsync("http://123.57.7.202/yamiap", cookie);

while (!task.IsCompleted)
{
continue;
}
bool b = task.Result;
});
}

}
}


下面是加载的页面的代码
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
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;
using YaMiClient.Framework;
using YaMiClient.Models;

namespace YaMiClient.Views.WorkViews
{
[Screen(Name="WorkList")]
/// <summary>
/// WorkList.xaml 的交互逻辑
/// </summary>
public partial class WorkList : ChildScreen
{
private ObservableCollection<NavigationModel> navigationSource;

public ObservableCollection<NavigationModel> NavigationSource
{
get
{
if (navigationSource == null)
navigationSource = new ObservableCollection<NavigationModel>();
return navigationSource;
}
set
{
SetProperty<ObservableCollection<NavigationModel>>(ref navigationSource, value, () => this.NavigationSource);
}
}

public WorkList()
{
InitializeComponent();
//保证窗体显示在上方。
NavigationSource = new ObservableCollection<NavigationModel>();
NavigationSource.Add(new NavigationModel() { NavigationName = "动态", Url = "http://123.57.7.202/yamiapi/wechat/dynamic/alldongtai.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Dynamic.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "日历", Url = "http://123.57.7.202/yamiapi/wechat/calendar/calendarList.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Calendar.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "任务", Url = "http://123.57.7.202/yamiapi/wechat/task/myUnfinishedList.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Task.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "通知", Url = "http://123.57.7.202/yamiapi/wechat/notice/gu_dtzliebiao.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Notice.png" ,IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "群组", Url = "http://123.57.7.202/yamiapi/wechat/group/aqzliebiao.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Group.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "知识库", Url = "http://123.57.7.202/yamiapi/wechat/repository/fileList.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Knowledge.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "审批", Url = "http://123.57.7.202/yamiapi/wechat/apply/fshenpi.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Approval.png",IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "工作报告", Url = "http://123.57.7.202/yamiapi/wechat/workpaper/mySendList.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/WorkReport.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "资讯", Url = "http://123.57.7.202/yamiapi/wechat/consultation/zixunall.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/Refer.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "打卡", Url = "http://123.57.7.202/yamiapi/wechat/punchcard/byiji.jsp", NavigationImage = "pack://application:,,,/Assets/WorkImage/PunchCard.png", IsWebBroswer = true });
NavigationSource.Add(new NavigationModel() { NavigationName = "聊天", Url = "http://182.92.97.9/yamiweb/huanxin-webim2/index2.html#", NavigationImage = "pack://application:,,,/Assets/WorkImage/PunchCard.png", IsWebBroswer = true });

}

public override void OnActivity()
{
base.OnActivity();
}

private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var target = sender as ListBox;
if (target == null)
return;
var item = target.SelectedItem as NavigationModel;
if (item == null)
return;
Dictionary<string,object> parameter=new Dictionary<string,object>();
parameter.Add("NavigationUri",item.Url);
parameter.Add("Title", item.NavigationName);
Activate("WorkDetail", parameter);
}

}
}


主要就是用单例模式,实现web端 已实现功能的直接嵌套,不知道为什么加了页面之后 就一直闪烁


...全文
611 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kiddkyd 2016-07-19
  • 打赏
  • 举报
回复
我也出现了,貌似是用了css3的动画导致
chloette0921 2016-07-01
  • 打赏
  • 举报
回复
同问~~~有人知道么

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧