Determine how far WP WebBrowser has loaded - c#

I am working on an alternative browser for Internet Explorer Mobile on Windows Phone. My problem is that I also want a progress bar displaying how far a page has loaded just like Internet Explorer mobile has but I cannot find any property or event on the WebBrowser control that tells me how far a page has loaded. Is there something that I can do?
PS. This project is mainly for Windows Phone 8 so some WP 8 exclusive apis can be used but WP7 support would also be nice.

A loading bar is as simple as determining the total number of kb's to be downloaded at the start of the request and then updating the progress bar with the current downloaded kb's (as a percentage).
Luckily, you can just add a progressbar like this:
<ProgressBar Foreground="Green" x:Name="ProgBar" Visibility="Collapsed" IsIndeterminate="True" Height="10" HorizontalAlignment="Left" Margin="10,66,0,0" VerticalAlignment="Bottom" Width="460" />
You then need to modify your main page.cs to incorporate the event:
void Browser_Navigating(object sender, NavigatingEventArgs e)
{
ProgBar.Visibility = Visibility.Visible;
}
void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
ProgBar.Visibility = Visibility.Collapsed;
}
You can read how this all works ON THIS LINK. (This link shows a tutorial which will exactly explain to you how to accomplish this progress bar)
What you could also do is make use of the Windows phone 8 Progress Indicator as they do in this example.
Mind you that in general, in C#, (or any programming language) you can ask for the total number of kb's (e.g. with WebClient) like this. Then you could write a timer that checks the current amount of downloaded kb's and update the progress bar every 0.x seconds.
I hope that helps you out. Good luck!
Update
If you search for page loading bar c# you get multiple useful links that show you how to build a loading bar for a webbrowser.
For example:
http://code.msdn.microsoft.com/wpapps/Custom-Indeterminate-833d783d
http://github.hubspot.com/pace/docs/welcome/
How to make progress bar works while web browser navigating?
How to show progressbar until WP8 WebBrowser control loaded the URL?
But especially this one could be very useful:
http://tekkieblog.com/develop-simple-web-browser-with-progress-bar-using-csharp/
It states that you can use the built-in Status Strip control to get the required loading bar. The step to windows phone shouldn't be all that big from this C# snippet.
The proposed method is:
This simple Tutorial will help in adding up a Progress Bar to your Web browser using C#. In the design view, drag and drop the Status Strip control from the Tool box. The Status Strip control will be displayed at the bottom of your Form. Select the Status Strip control on the form. Click the Drop Down list and select Progress Bar. The progress bar control will be displayed in your Form.
Right click the Web Browser Control in the design mode and select Properties and then select events in the Properties window and move to Progress Changed event and double click it. Add the following code snippet:
private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
{
ProgressBar.Maximum = Convert.ToInt32(e.MaximumProgress);
ProgressBar.Value = Convert.ToInt32(e.CurrentProgress);
}
So what they basically do is convert the current progress to a number such that you get control over the percentage.
You can also do it differently:
I HIGHLY RECOMMEND you watch this link: http://www.youtube.com/watch?v=KHQCtunR2QI
That video must definitely answer your question!

void Browser_Navigating(object sender, NavigatingEventArgs e)
{
ProgBar.Visibility = Visibility.Visible;
}
void Browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
ProgBar.Visibility = Visibility.Collapsed;
}
you have to collapse visiblity of progressbar for more events
navigation_failed event
browser loaded event not navigated event

Related

WP8.1 Navigation Bar Overlay

I am currently developing an application in windows phone 8.1 And I am having problems with the soft system navigation bar.
I can hide the bar, but I can't seem to find if it is visible or not.
To hide it, I could use:
ApplicationView.GetForCurrentView().SuppressSystemOverlays = true;
The problem is that some phones have it, some don't. I need to find if it is active so that I can bind the height of my VirtualizingStackPanel correctly.
Thank you,
As far as i know there is no perfect way to work with the none-hardware nav bar, and i think that your best option here is to subscribe to the ApplicationView.VisibleBoundsChanged event,
so basically what you need to do is :
set the ApplicationViewBoundsMode to UseCoreWindow so that the content will be laid out in the region occupied by the core phone window :
ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
subscribe to the VisibleBoundsChanged event and handle you UI changes inside the handler:
ApplicationView.GetForCurrentView().VisibleBoundsChanged += handler;
//...
private void handler(ApplicationView sender, object args)
{
//handle ui changes
}

C# WPF Frame->UserControl->Usercontrol Loaded event doesn't fire

I'm new into WPF and have a problem I can't seem to find a solution for.
I'm writing a G19 (Keyboard) applet. This Keyboard has a 320x240 display attached, which you can access with C#.
I'm using WPF for this, because I don't need to do any GDI drawing anymore and use the normal controls instead.
So. It works as I wish. Everything draws properly except one UserControl. I have downloaded this control -> http://marqueedriproll.codeplex.com/
In the designer, the control works, the Loaded event get's fired and the animation is good.
When I run my application, I just see the label and the text. The animation does not work, and the Loaded event does not fire anymore.
Any help is appreciated.
The main function is my wrapper. The wrapper is already a Usercontrol and displays plugins which are switchable. This wrapper has the Frame Control(Wrapper1). I replace the content of this frame every time I switch the plugin.
public void SetPlugin(IPlugin plugin)
{
if (this.MainPlugin != null)
{
this.MainPlugin.OnHide();
((UserControl)this.MainPlugin).Visibility = System.Windows.Visibility.Hidden;
}
this.MainPlugin = plugin;
((UserControl)this.MainPlugin).Visibility = System.Windows.Visibility.Visible;
this.MainPlugin.OnShow();
this.Wrapper1.Content = this.MainPlugin;
}
I think it's the right approach to handle a plugin system that way. The plugin get's drawed on my keyboard.
What I don't understand is why the usercontrol only works in the designer view and not in the running application.
The basic code of the scrolling label is so:
public MarqueeText()
{
this.Loaded += new RoutedEventHandler(MarqueeText_Loaded);
InitializeComponent();
canMain.Height = this.Height;
canMain.Width = this.Width;
}
void MarqueeText_Loaded(object sender, RoutedEventArgs e)
{
StartMarqueeing(_marqueeType);
}
I don't see a reason why it doesn't work. Actually Ive always found a way to fix a problem but this time I see nothing.
Thanks in advance. Your help is really required today.
Have a great saturday! :)
I am guessing you are rendering to a bitmap target, rather than onscreen. If you are using RenderTargetBitmap, you have a couple of responsibilities. You need to set both a presentation source, and make sure you run events on the dispatcher.
Normally, App.xaml or Application.Run does this for you, but if you are not using a Window, you are on your own.
See this related question for details.

Progress bar in Windows 8 XAML/C#

Would be really helpful if someone could tell me which event handler I need to use when a webpage is/has loaded using Windows 8.1, as well as the C# code for making the web page progress show up in the progress bar.
EDIT: Apologies if this isn't clear. This is for windows store apps rather than windows forms. I'm coding with C#, and i'm wondering how to implement the progressbar to the webbrowser(webview) so that it is updated dependent on the progress of the loading page.
Thanks.
See these answers:
WPF WebBrowser: How I do access progress and new window events
Determine if WPF WebBrowser is loading a page
If you are with no time, you can simply put a Indeterminate Progress bar, until you code a refinated Progress code.
<ProgressBar Name="pb1" IsIndeterminate="True" Visibility="True" />
void theBrowser_Navigated(object sender, NavigationEventArgs e)
{
//Console.WriteLine("Webpage Loaded !!");
pb1.Visibility = Visibility.Collapsed;
}

C# Showing Buttons on taskbar thumbnails

In WMP, I have been shown buttons on the taskbar thumbnail. How can I make them for my winforms app in C#?
The WindowsAPICodePack contains a control called ThumbnailToolBarButton that you can use to get this functionality going.
You'll need to make sure you have icons for each of the buttons (as I don't believe you can put text on them), and then it should be a simple matter of creating new controls and adding relevant event handlers.
Sourced from here.
XAML
<Window.TaskbarItemInfo>
<TaskbarItemInfo>
<TaskbarItemInfo.ThumbButtonInfos>
<ThumbButtonInfo ImageSource="/IconProgressDemo;component/Icon1.ico" Description="Play!" Click="ThumbButtonInfo_Click" />
<ThumbButtonInfo ImageSource="/IconProgressDemo;component/Icon2.ico" Description="Stop!" Click="ThumbButtonInfo_Click" />
</TaskbarItemInfo.ThumbButtonInfos>
</TaskbarItemInfo>
</Window.TaskbarItemInfo>
C#
private void ThumbButtonInfo_Click(object sender, EventArgs e)
{
MessageBox.Show((sender as System.Windows.Shell.ThumbButtonInfo).Description);
}
I haven't tried this hope this will be helpful.
and refer these links.
http://www.zayko.net/post/Adding-Buttons-to-Window-Thumbnail-in-WPF-4-for-Windows-7-(C).aspx
http://msdn.microsoft.com/en-us/windows7trainingcourse_win7taskbarmanaged_topic2.aspx
http://msdn.microsoft.com/en-us/magazine/dd942846.aspx
and there is Taskbar API available you can try with that.

Multiple XAML layouts in WPF

App I am trying to create in WPF/C# has quite a few buttons in a layout with a "TV screen" type panel above (its actually an FMS emulator for commercial aircraft). Many of the buttons change the layout, which are numerous TEXTBOXs on the tv screen. My question is: is there a provision to encapsulate the layouts in different classes/files and load them into the "tv screen" at the selection of the various buttons? In other words, user hits the Flight Plan button and the layout of the 355x355 box (screen) above loads the XAML "flight_plan" layout/file/class. Each layout has different TEXTBOX sizes & locations and there are in excess of 30 different "pages", which would make encapsulating them desirable.
I am very new to WPF and c#, but have written win apps in c++ all the way back to Turbo C & OWL. I also may be trying to do something that isn't possible due to working lately in Android/Java and am confusing capabilities.
Thanks in advance.
Edit
Thanks to #adityaswami89 and everyone else who got me on the right track, I have found the solution. I added the pages via a new "WPF Page" in VS2012. Then changed the "screen" to a navigation frame and it was truly simple from there. Below is the simple project I created to test it.
public partial class MainWindow : Window
{
NavRad navrad = new NavRad();
FPlan fplan = new FPlan();
public MainWindow() {..}
private void Frame_Navigated_1(object sender, NavigationEventArgs e) {..}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Screen_Frame.Navigate(fplan);
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Screen_Frame.Navigate(navrad);
}
You can also use the concept of Frames for the intended functionality , if that can be an option you are looking.
You can refer the below link for the same.
http://msdn.microsoft.com/en-us/library/ms750478.aspx#Frame_in_Standalone_Applications
You can abstract the different UI Layout Sets within different User Controls and load them according your UI logic. One way to do this is using an MVVM framework, for example, Caliburn Micro makes this a pretty simple task as doing:
ActivateItem(UILayoutViewModel);
And this call can be called from any method.
See more of Caliburn Screens and Composition at official source.

Categories

Resources