Control the VerticalOffset of a webbrowser in windows phone - windows-phone-7

I am using the webbrowser to show some string with a appbar-button. When I click the button, the webbrowser will NavigateTo another string. Everything goes well except that once the webbrowser is scrolled down(When the user is reading the end of a article), when the button clicked, the webbrowser is still at the bottom, the user has to scroll the webbrowser up.
So, before the new article is loaded, I want to set the verticaloffset of the webbrowser to zero. But there is no scrollviewer in the webbrowser, so I can't use the ScrollToVerticalOffset method.
would anyone know how to Control the VerticalOffset of a webbrowser?
Thanks.

You can do this via InvokeScript, which allows you to invoke JavaScript within your page. If you add the following JavaScript function:
function setVerticalScrollPosition(position) {
document.body.scrollTop = position;
}
Then invoke the following (C#)
this.webBrowser.InvokeScript("setVerticalScrollPosition", this.vScrollPos.Text);
Your browser control should scroll (courtesy of this blog post)

Related

Toolbar Button and SendMessage() Function Difficulties

I want to make a program (program 1) that will click a toolbar button on another program (program 2). I have the handle of the window the toolbar button is in and I have its button ID. At first I thought I could use the function:
SendMessage (buttonHandle, BN_CLICK, 0, 0);
but I have no clue as to how to get the handle of the tool bar button. I tried to use the function:
GetDlgItem ( windowHandle, buttonID);
but it doesn't work. I also have been told that since it's a toolbar button, there is no specific handle for it... kind of odd, not sure how that works...
Question 1:: is there a handle for toolbar buttons and how may I get it?
Question 2 (MAIN AND MOST IMPORTANT QUESTION!):: what function can I use to click on a toolbar button? (please mention the parameters for the function too)
Is there a handle for toolbar buttons and how may I get it?
No. Toolbar buttons are non-windowed. They do not have window handles.
What function can I use to click on a toolbar button?
You use UI Automation to automate other applications.

Windows Phone Navigate Progress Indicator

I am currently having problem with my Windows Phone 7 app. I have two pages:
- First contains checkbox and button to navigate to next page
- Second contains some controls with data that take about 3 seconds to load
So basically what happens now if user presses a button on first screen, it takes 3 seconds to navigate to second screen. I would like to add ProgressIndicator during this navigation process, but it dissapears, so it looks like i need to await navigation to the page. Can someone propose a way how can i do it:
prog.IsVisible = true;
prog.IsIndeterminate = true;
SystemTray.SetProgressIndicator(this, prog);
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
SystemTray.ProgressIndicator.IsVisible = false;
You shouldn't place the progress indicator on the page you are navigating from, but rather on the page you are navigating to. So override OnNavigatedTo in the destination page and show indicator there.
Also, what is the source of this slowness? Is the page heavy with controls? Are you loading something from storage/internet? You should do that asynchronously if you aren't already.

WebBrowser as ListItem and scroll

This question about WP8 project.
I have a LongListSelector with pictures and html formatted text below. Currently each pictire implemented as an Item of the list. The last Item with browser has its own template and shows WebBrowser instead of picture.
I am expected this item behave such as TextBox which I can scroll by interacting with LongListSelector.
But this WebBrowser has it's own scroll inside and intercepts any surrounding scrolling events. Thus whenever I scroll down the list to show WebBrowserControl to the whole screen, I can't go back to the pictures.
Please help me with this issue. What is the appropriate solution? I need a separate pictures since want to implement "Clicked" logic on top of it. And I want to have WebBrowser too (but prefer to behave it similar to RichTextBox (which I can't find in WP8))
USE ListBox.ItemTemplate along with DataTemplate and inside dataTemplate we could custom create xaml tag !

WebBrowser disable copy paste

I have a several question about WebBrowser control into WP7.
How to disable word selection by a click?
How to disable vertical scrollable by a gesture?
Add some extra styles to your html pages and render it on WebBrowser control
body {-ms-user-select: none;} use this css code to disable word selection by tap
in IE on Windows phone 7/8
body {-ms-touch-action: none;} use this css code to disable vertical scroll
in IE on windows phone 7/8
hope this work fine for you.
first , u can get a border control which is the container of the ie9 mobile core using visual tree helper
then
Q1: u can cancel the "Tap" gesture occurred in border control before it was passed to ie core
Q2: u can cancel the "DragDelta" gesture for some direction or distance ,well ie. vertical scroll.
The answer to Copy and Past = "I don't believe you can stop it from occurring, unless its your webpage and you can set it up for a Read Only Document."-If i am wrong please correct me.-
the answer to Vertical Scrollable By a Gesture = "You could build the Gesture to Return a Null instead of the event value, Pretty much tell it that if this occurs then Cancel it....Return Nothing!"
You can achieve disabling selection using javascript:
function DisableSelect() { var handler = function (e) {e.returnValue = false;} document.body.attachevent('onselectstart',handler,false);}
and than calling from your code:
wb.InvokeScript("DisableSelect");
Don't forget to detach the event.

Windows Phone 7 - Move Content above Keyboard

I have page containing 4 textboxes and a button. The content is within ScrollViewer. When user goes to the last textbox, the button below it is 50% visible. So, to click it, user has to click on non-focusable area to hide the keyboard and then click on button.
Is there any way to move the ScrollViewer up? Or move the content up so that the button below focused textbox can be seen 100%?
The solution is to remove the buttons on the page and replace them with buttons in the ApplicationBar as this is always viewable below the SIP.
If this is not a solution you can implement (from a design view-point there is no reason to not do this but sometimes these decisions come from elsewhere) then you could look to use the ScrollToVerticalOffset method to try and bring the desired item into view.
I would suggest you read Alex Sorokoletov's article on how to transform the view. It might be of help for your problem.

Resources