注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

姑射道人的博客

博客新地址:nixuchen.com

 
 
 

日志

 
 

windows phone webBrowser改变白色背景  

2013-07-17 12:37:35|  分类: windows phone |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
As we all know, in the development of WP7, WebBrowser control function nice.Basic applications, used to display long text is the very good choice, especially the webpage crawling content display.Senior application, you can use the html/css/js to create cool effect.The garden on the WebBrowser a lot of good articles, it is worth learning.I am here to share WebBrowser encountered in the development of two tips, which belongs to the basic WebBrowser control applications, we hope to help.

One, the use of WebBrowser

Xaml

< Grid x:Name= "ContentPanel" Grid.Row= "1" Margin= "12,0,12,0" >

< phone:WebBrowser Name= "webBrowser" Margin= "12,0,0,0" />

< /Grid>

Code

Public partial class MainPage: PhoneApplicationPage

{

/ / constructor

Public MainPage ()

{

(InitializeComponent);

This.Loaded = new RoutedEventHandler (MainPage_Loaded);

}

Private void MainPage_Loaded (object sender, RoutedEventArgs E)

{

String content = "If you shed tears @ when you miss the sun, you also miss the stars";

String rawHtml ="";

RawHtml = "< html> < body>";

RawHtml = content;

RawHtml = "< /body> < html>";

WebBrowser.NavigateToString (rawHtml);

}

}

WebBrowser controls the background color default is white, in the control properties cannot be modified.If the application of the overall background color is black, WebBrowser controls are not coordinated, so how to modify the display?

Two, modify the WebBrowser control the background color

As we all know, the WebBrowser control is actually a browser page, the page display is also controlled by HTML, here comes everybody may already know: use the bgcolor property to control the background color.

Code:

Private void MainPage_Loaded (object sender, RoutedEventArgs E)

{

String content = "If you shed tears @ when you miss the sun, you also miss the stars";

String rawHtml ="";

If (IsThemeDark ())

{

RawHtml = "< html> < body bgcolor=\" #000000\ "> < p>";

}

Else

{

RawHtml = "< html> < body bgcolor=\" #FFFFFF\ ">";

}

RawHtml = content;

RawHtml = "< /p> < /body> < /html>";

WebBrowser.NavigateToString (rawHtml);

}

(private bool IsThemeDark)

{

Visibility darkBackgroundVisibility = (Visibility) Application.Current.Resources["PhoneDarkThemeVisibility"];

Return darkBackgroundVisibility = = Visibility.Visible;

}

  use the IsThemeDark to determine whether the current Application's default background color is it right? Black, keep the WebBrowser control the background color and the App default background color consistent.Examples of App use the default black background, operation, found in dark, Tagore disappeared, why returns to a thing?The original WebBrowser of die hard, font color or black, but I also know a little HTML, continued:

Private void MainPage_Loaded (object sender, RoutedEventArgs E)

{

String content = "If you shed tears @ when you miss the sun, you also miss the stars";

String rawHtml ="";

If (IsThemeDark ())

{

RawHtml = "< html> < body bgcolor=\" #000000\ "> < p>";

RawHtml = "< font color=\" #FFFFFF\ ">";

}

Else

{

RawHtml = "< html> < body bgcolor=\" #FFFFFF\ "> < p>";

RawHtml = "< font color=\" #000000\ ">";

}

RawHtml = content;

RawHtml = "< /p> < /font> < /body> < /html>";

WebBrowser.NavigateToString (rawHtml);

}

Code fragment of text color for the WebBrowser control will change the background color of the color.

If you follow the author runs above code, you'll find out the WebBrowser control in the loading process flashed, white background flash, it seems it is easy to change rivers,.How can let WebBrowser controls do not expose the tusks white “ ”?

Three, prevent the WebBrowser control loading during flicker

Generally analyze the causes of the occurrence of flicker.WebBrowser controls its own background color is white, loading our HTML, background was changed to black.Then in the WebBrowser control to display the HTML later, prior to the completion of loading, the WebBrowser control will appear white.This period of time is short, but still we were sensitive eyes to capture.The reason is clear, we will consider a solution: what we want is to load the HTML after completion of the WebBrowser, before what he looked like, we don't care, since care, simply hide away, you guess compared and nine in ten.

Xaml

< Grid x:Name= "ContentPanel" Grid.Row= "1" Margin= "12,0,12,0" >

< phone:WebBrowser Name= "webBrowser" Margin= "12,0,0,0" Opacity= "0" LoadCompleted= "WebBrowser_LoadCompleted" />

< /Grid>

Set the WebBrowser control's Opacity property to 0, will be hidden by default.Handle the LoadCompleted event.

Code

Private void WebBrowser_LoadCompleted (object sender, NavigationEventArgs E)

{

WebBrowser.Opacity 1.

}

In response to the LoadCompleted event, the WebBrowser control after loading, to be displayed.Run, the effect is good, the whole world peace.

  four, summary

Here to share the set the background color and prevent flicker, but WebBrowser encountered in the application of basic problems, such as when loading Chinese garbled and other issues, can go into the garden and search for other articles.Having said that, the function of WebBrowser nice, in particular, mango adds support for HTML5, developers can use HTML5 technology based on WebBrowser to create a more personalized Native application.More important is, based on the development of HTML5 is a cross platform.Many open source projects in support of WP7, such as JQuery.Mobile, PhoneGap etc..Everybody is free to try.

Download code

(the end)

 
  评论这张
 
阅读(879)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017