How to avoid blinking when calling NavigateToString in WP7 Silverlight WebBrowser Control - silverlight

I need to render some Rich Text in the screen that needs to change following a timeline. In my iOS version I use the Web control and in Android version I use TextSpan.
I read some recommendations where people state that the WebControl is the best way to render rich text in Windows Phone 7 so I have a WebBrowser control that I populate with an HTML string. Everything works fine until I decide to programmatically change the content with a call to NavigateToString. The content gets changed but with a brief blink to a white screen in between.
As my program needs to update the contents of the WebBrowser control several times per second the screen turns all white from all the refreshes.
I am considering the painful idea of using TextBlocks with inline and LineBreaks but I will have to convert my HTML manually so I wanted to try to see if someone knows how to do this.
To replicate the issue just place a WebBrowser control on a page and update the content with NavigateToString to see the white transition blinking

I do a combination of OnNavigated and javascript. I start with Opacity = 0 and load a placeholder page into the control.
<html>
<head>
<script type="text/javascript">function setContent(s) { document.body.innerHTML = s; } </script>
</head>
<body></body>
</html>
In OnNavigated I set Opacity = 1 then I use InvokeScript to load my actual content.
webBrowser.InvokeScript("setContent", myContents);
In my case I am filling the entire page contents, though you might be able to write a more targetted piece of javascript if you are only changing certain pieces of the page.

The behavior is normal because the WebBrowser control basically has to re-render the entire page, even if you changed small parts of the content. Your best choice would be using RichTextBox - this will involve some manual text format processing.

I was going to suggest this:
WB_OnNavigating --> visibility = collapsed
WB_OnNavigated --> visibility = visible
Or a play on opacity. But these may be too slow given the multiple refreshes per second. Still may be worth a try to see what you get.
Is there any way the XAML background could be white or the HTML content's backcolor could match the page background?
Still looking for a better answer..

Related

How to change the View Mode of DocumentViewer

How can I change the View Mode of DocumentViewer?, I want the page to be full width since the beginning.
If I use documentViewer.FitToWidth() it does stretch but not completely.
If I use ctrl+2 it stretches completely and thats what I want to achieve programmatically or using xaml if possible.
Thanks
I found the problem.
I used FitToWidth() too early (right after documentViewer.Docuemnt = document), I changed it - now I call it after the documentViewer loaded and it works fine.
I guess it was my fault - I dont understand why it stretches it almost completely when I call it right after I load document but w/e as long as it works.

Images and HTML in WPF app

I have a WPF application where I have a column that should display one of the following:
If images are returned, display the images.
If a HTML text is returned, render the HTML table within the cell.
Can someone please tell me how I can do that?
For HTML, you may refer this link - http://pdgp.wordpress.com/2008/05/31/show-html-formatting-in-gridview-cells/
For showing Image, you may refer here - http://msdn.microsoft.com/en-us/library/2ab8kd75.aspx
Hope this helps.
[Update for Winforms DataGridView]
In order to display HTML, the only choice would be to override the Paint method I suppose. Alternatively, you may think of hosting a WebBrowserControl.
How to: Host Controls in Windows Forms DataGridView Cells:-
http://msdn.microsoft.com/en-us/library/7tas5c80.aspx

Forcing Arrange in a Custom WPF Canvas

I'm working on a project that involves creating a custom graphical editor. The graphical editor has multiple tabs, and I want to create a preview function that will show a popup with Bitmap previews of the content of each of the tabs. However, the problem I'm running into is that the content for each of the tabs must be arranged before a proper preview can be generated for it. This means going into each of the tabs to ensure that they're rendered and arranged. Then, and only then, do the previews get properly generated, otherwise the previews have a size of 0x0. Does anybody know how to force an arrange of a content control so that I can get a properly sized preview generated ?
Apparently you can just call the 'Arrange' method directly, but you have to be careful about the rectangle you pass in as a parameter, because it can adversely affect the display of your control if you just want to force the object to draw itself (ie can force it to draw out of the desired position).
Here is a link to MSDN where it discusses the "arrangeOverride" method of a control.
I'm not sure this is what you need, but this method seems to be what you're asking about.
Hope this helps!

A better way to show different wpf pages in mainWindow?

I have several Wpf pages in my project, these pages have different forms and ui control indide theme. The image below shows the mainWindow and there are two button.
I want to show a specific page when I click on + or Edit button using the Frame control which is highlighted.
apparenatly this woks:
Page1 me = new Page1();
mainFrame.Content = me;
But it has an IE navigation sound and a toolbar appears after going to page2.
any better way to show diffrent pages and not using a frame?
You may want to convert the Page into a UserControl. You can then put that control inside some other container, such as a Grid. You'll have to manually swap out the pages in the container when navigating, but it looks like you're doing that anyway.
The purpose of the Frame control is to allow navigation. If you don't want navigation, then don't use Frame. You can turn off the navigation toolbar, but that won't actually disable navigation - there are mouse buttons and keyboard shortcuts for navigating back.
If you just want to host a UI element without navigation, use something simpler, like a Border element - put the content in its Child property. You can change the Child as many times as you like at runtime.
I was able to set the frame control's NavigationUIVisibility to Hidden. This solved the problem for me. I am using Visual Studio 2010 though so it might not be applicable to older VS versions.
Ian Griffiths, what you suggest increases the workload on the developer substantially. And you are stepping outside of the underlying paradigm of XAML.
In my case I'm developing a game application and have chosen WPF as the UI platform as much as possible. For me that means a intro screen, character select, etc. The purpose of Pages is to encapsulate the navigational need of such an application.
I suspect your downvote is due to your statement "If you don't want navigation...". Upon re-reading the original posters question I see he does want navigation, he just wants it on his own terms. I would have voted you down too. YotaXP's solution neglects the issues with using a User Control, particularly if it may contain other User Controls. It looks like Chris Calvert came up with an actual solution to the poster's issue within the parameters of the problem.
I would be curios if I could override the navigation hotkeys and such within the existing paragimn but that's properly in its own thread.

Tag cloud control for WinForms .NET 2.0+

How would you render a tag cloud within a .NET 2.0+ WinForm application?
One solution that I am thinking of would be using the WebBrowser control and generating to some ad-hoc HTML, but that seems to be a pretty heavy solution.
Am I missing something more simple?
How about creating a user control that implements the Flow layout control? You could have a method for "Add(string tagName)" that would create a link label on the fly and add it to the Flow Layout control. The Flow Layout works just like the web, in that controls added to it are put in the order of creation.
Then you only have to add some logic to resize the Link Label based on hit count for that tag.
Well, you'll want a control with these major features:
Automatic layout of variable sized string snippets
Automatic mouse hit testing
Those are a bit hard to come by in WF controls. A RichTextBox with ReadOnly = true gives you the automatic layout, but not the hit testing. A ListBox with DrawItem can give you variable sized strings and hit testing, but not a natural layout.
I think I would use RTB and make hit testing work with the MouseDown event and GetCharIndexFromPosition(), reading back the tag at the clicked location. You'll need a bit of logic to find the starting and ending white space around the word.

Resources