Awesomium webcontrol - c#

So I've been trying to use something other than IE for my webcontrol in a side-project of mine (C#, WPF project type) and I was looking around for alternatives and have tried in the past but failed to implement them.
I decided to try again and implement awesomium, however it is still confusing as always and doesn't have any straight forward examples for me to use as a base.
Would someone be able to show me how to implement awesomium for a webview/webcontrol? My vision is to have it navigate to a shoutbox website, and while my application is still open to keep it there (i.e not refresh it so that it doesn't lose anything) as it is being shown in the space of tabitem.

I have used Awesomium, but the last version I used was 1.6.1, and there are some differences between that and the current version - they've actually made things easier.
The documentation says that you should be able to force navigation of the control simply by setting the Source property:
<osm:WebControl Name="webControl"
Source="http://www.google.com/"
/>
If you find the Source property is not bindable then simply revert to using some code behind in the view - subscribe to a property change event from the viewmodel (or from an event broker if you are using one), and change the Source property in response to an event.

I believe, the problem with the Source property is that if you are setting it to the same URI to refresh, it won't refresh because of a bug. It is documented on their github page and their answers page.
As workaround, to refresh your page correctly you need to pass a fake URI first and then your page again to your binding property, like this:
CurrentSource = "FakeUriString".ToUri();
CurrentSource = "http://www.yourpage.com".ToUri();
Keep in mind, my current version of Awesomium is 1.7.4.2 and they may fix this issue in the future as they stated in their issues page.

Related

Prism for Xamarin.Forms unable to AutoWire

I am trying out Prism.Forms for my next client project. Unfortunately, I am seeing a strange behavior with my samples.
Pretext
It seems like XF or Prism does not like me including an existing XAML page (also mentioned by Brian Lagunas - The man - himself at the Evolve session). But renaming a page also throws it off and the ViewModelLocator can't seem to locate the ViewModel anymore. Even if I re-create the page with same name, It can't find it ViewModel. Manually setting the BindingContext works, but I am trying not to create my dependencies for constructor injection.
Question
While working on existing code, a minor change caused NullReference exception when using NavigationPage as a root. Here is an example of a working sample app
https://github.com/hnabbasi/xamarin/tree/master/XFPrism/XFPrism
I am using a NavigationPage and pushing a ContentPage. Then I push another ContentPage, then I show a Modal page via button click and communicate. I send parameters back to Second content page via NavigationParameters.
To break it, simply try to swap the ISayHello service with IPageDialogService. I am not sure what's going on that's breaking it.
Thanks in advance :)
The INavigationService is a named type and as I recall a known limitation of Unity is that named types must precede unnamed types.
As mentioned by Dan S. in the comments. The MainPage is not set when I was calling the PageDialogService to display the alert, hence the NullReference.
In case you really need to do something like this where you want to somehow wait for something to finish before doing an operation, try Task.Yield().
I fixed my scenario as below,
// will yield for current operation of page appearing
await Task.Yield();
// by now, the page has appeared and set, so this should work fine
SayHiCommand.Execute(this);
I have used this workaround in the past. If you know a better way of handing this, please comment away.

Windows Phone browser live html modification

I haven't looked into it very much but am struggling to find relevant information on the topic. I basically want to create a browser that applies a filter to a webpage by changing colors in a webpage. My guess is that I will have to change the html once loaded or something, would this work? Do I have other options?
PS. I don't just want to make every color darker, I would more like to invert the colors.
Edit:
If any you were wondering, I am talking about the XAML browser component that can be used in a Windows Phone application.
I think the simplest way to do that is to inject some Javascript into your page once it has loaded.
To do that, you need to set the IsScriptEnabled to true on your WebBrowser control and then subscribe to the Navigated event.
When that event occurs you can inject some JS codeby using the WebBrowser.InvokeScript method.
Here is an example of JS code that darken the page : JavaScript: Invert color on all elements of a page
If you are talking about in a PC internet browser, you can find an add-on to execute Javascript automatically, such as Greasemonkey for Firefox. If you are talking about Windows Phone's Internet Explorer, I don't really know what you could do there, as I don't think they allow add-ons.

RadToolTip's RenderControl method

I have an asp.net application which uses the web part framework to allow users to customise their interface. One of the features of this is a catalog of available web parts, one is provided by default, but it can be overriden if you wish to change the layout, etc.
override void RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart)
That, as far as I can tell, is the only way to do it. At the moment I'm creating a panel with all the necessary elements in it, and using the panel's RenderControl method to output it to the htmlwriter. So far, so good. The problem occurs when I try to add a radtooltip to my panel, using the same RenderControl method, and I get the following runtime error:
Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.
I can see why this might be a problem, since the tooltip presumably uses javascript and has to write it to the page - but the RenderCatalogPart method has no knowledge of which page it's going to be outputting to. Is there any way around this or am I going to have to come up with an alternative?
I've posted this on the telerik website but though I'd ask here as well incase anyone has any ideas.
Thanks.
The Telerik ASP.NET controls require a MS AJAX ScriptManager control. I suppose that's why they want to access the page as well - to get a reference to the ScriptManager. Try setting the tooltip's RegisterWithScriptManager property to false and see if the control renders then.
The issue here is that the ToolTips must be created and added as controls in PreRender, so that it can add it's script to the ScriptManager.
Creating a collection of tooltips in the PreRender() method and then writing them to the httpwriter as shown above in RenderCatalogPart fixes the problem.

Problem dropping item on WebBrowser component

I would like to drop some controls from a self-defined toolbox onto a WebBrowser component. Because this component doesn't support drag-drop I use a wrapper to catch DragEnter, DragOver, ... This method worked fine while the application was still configured to work in .NET framework 2.0.
For some reasons I had to upgrade to .Net framework 4.0. All drag and drop functionality with my wrapper is broken. No events are triggered whatsoever. Events like "navigated" are still working fine...
I allready searched for possible answer and tried a few things but I couldn't fix it. Does anybody has any clue? Currently I'm thinking about implementing the wrapper given at: Codeproject
Thanks for your time!
EDIT 1 (& 2):
I continued my search for answers and discovered the following stuff:
The DragEnter-event should be fired somewhere because the right icon appears on the browser. This icon only seems to appear when a DragDropEffect is set correctly. But I can't find the handler for the DragEnter-event (or other).
I tried to drop the wanted item onto an other screen part. This part of the screen doesn't contain a lot of components so it was pretty easy to implement the drop-action there. And it worked fine. I was able to get the object out of the eventArgs. But it's still not working on the webbrowser-component.
Maybe these clues can help you to sort out this problem.
The first way I actually got working is by adding some events and there handlers within javascript code. The events I've set are:
ondragenter
ondragover
ondragleave
ondrop (NOT ondragdrop !!!)
By handling these events within javascript and sending the event to C#-code I could handle these events as wanted.
To get to the control I'm dragging I implemented a little "clipboard". With this static class I'm able to hold the control I'm dragging and access it from the "onDragEnter"-code.

Handle navigation between several view in a WPF application

I've done several WPF application(not using MVVM) in the past and I had always to implement my own system of navigation between view(instantiate the view once, and then load in a container component, with refreshing required components of my view).
It works, but:
It's always custom, so if a new developer comes he has to learn of it how it works
I'm pretty sure that It's not the most optimized(most of things haven't been done in background worker, ...)
It's a time loss
So I was wondering if there is an official way to handle this ? I don't exactly how, but I was thinking to a navigation component, which can act a little like a tab panel, or a little like the MVC framework in asp.net, we can call a specified controller for an action and some parameters.
Maybe deactiviting bindings when they aren't in the current view
You can use DataTemplates/Styles to customize content of your control ( not only apearance, but data, cause that what you're asking for I presume)
http://msdn.microsoft.com/en-us/library/ms742521.aspx
You can have one Host control and at runtime change its appearance based on events/ states.
Like an example can have a look here:
http://code.google.com/p/svnradar/ how this program manages a appearance of Group and Flat view of repository information.
Another example:
Podder of Josh Smith
http://joshsmithonwpf.wordpress.com/2008/03/05/podder-v2-has-been-released/
Hope this helps.
You may be interested by Lakana, a lightweight (but powerful) framework that can handle for you all the navigation concerns !
Riana

Categories

Resources