Display html in Windows Store app - c#

I am trying to display an html in my Windows Store app (C#/XAML). But I cannot find an appropriate way to display it with the transparent background. Is there any way to get to know app background color and format html for WebView correspondingly? Or shall I better add another page for showing html-description, with setting its background to the one I would like beforehand (in code)? Or maybe there is some better approach?
P.S. I also would like to be able to handle hyperlink clicks, if it's possible. I know I can do so in WebView.

My understanding is that WebView controls are actually rendered as a separate surface on top of the XAML layer and consequently do not support transparency. Your best bet would be to do as you suggested: finding the current app background color and setting the WebView HTML's background accordingly.
Getting the app background color is easy; something like Resources["ApplicationPageBackgroundThemeBrush"] would do the trick.
Applying that color to whatever page you wish to navigate to is trickier, AFAIK. One method that might work (though I haven't tried it myself) is to use HttpClient to download the page's raw HTML and modify the background color prior to calling WebView.NavigateToString(), instead of directly calling WebView.Navigate().
If you can edit the page source, you could simplify the process by adding some JS scripts to change the background color, then use WebView.InvokeScript().

Related

Xamarin.Forms Change Background Color For Application

I want to change the background color for the whole application. I have been searching but I found nothing. Of course there's a way instead of changing the background color for each page right? Hope to get an answer soon. Thanks in advance.
You can look into Xamarin.Forms Shell where the Shell is the container of the entire application. This would enable you to have the background defined at only one area instead of every page. Furthermore, it would allow you to customize it for specific pages if need be.
You can find their example application using a Shell called "Xanimals" here.

C# Winform: Remove the border from a standard button?

Is it possible to remove the border of a standard C# Button ? I know that I could set the FlatStyle property to Flat and customize the FlatAppearance property to hide the border but I would prefer to use the Standard property to ensure that the control appears under all operating systems like a default Button. Did you have any suggestions how I can solve this issue? I am working with a Windows Forms Application.
You could use an image and make it clickable, that is one way to avoid the borders, but there are several options. Good luck!
If you are using windows forms and trying to implement Flat UI, Material UI, Metro-Looking controls, you're in hell. It is has limited properties for customizations unless you know how to work with Graphics and Animation. You'll have to use imagebox or picture box and dynamically change its image on different events.
I'll suggest WPF or Windows Presentation Foundation for a more customizable User Interface.

C# launch form when images fully loaded

I'm making C# application design with images, but when I launch it, I see loading images (~1sec), so how to make simple loader, when images (background, logo, etc..) fully loads, to show my app? I know it's possible but I don't know how to. Thanks so much!
This sounds like standard behaviour. The controls get painted one by one in z-order and if one is slow the rest may appear to flicker.
You could try double buffering the whole form as shown here:
How to fix the flickering in User controls
Alternatively you could suspend the layout while everything is drawn and resume it afterwards:
How do I suspend painting for a control and its children?

Pull image from BitmapCache WinRT

I have an application for the windows store that I need to make emulate the tabs like Internet Explorer. The problem is that I have one control and it won't load into both the AppBar and the main view.
Is there a way to setup the CacheMode in the constructor of the control and then pull a bitmap from the BitmapCache and load that in the tab view in the AppBar? Or am I going about this the wrong way. I don't want to use two different controls due to it being a hack I want this to work with one control.
I am writing this application in C# and XAML.
Any help is appreciated.
A control can only have one parent in all popular XAML technologies, so you can't put it in two places.
You can use RenderTargetBitmap to take a screenshot of a control and put it elsewhere in your layout, but there are plenty of problems with that
It uses additional memory to store the bitmap
You need to figure out when to take that screenshot - typically after all images load and after every layout or content update.
A bitmap is not interactive.
Your best bet might really be to have two copies of the same control. You can create a UserControl to encapsulate any functionality and properties and reuse that control in multiple places easily. If you reference an image by URI - the platform should automatically share the resources for the image used in multiple controls.

Can I use the WPF WebBrowser control as a UI interface in C#?

Is it possible to use the WebBrowser control as a UI interface in C#?
I like to write a string of HTML directly into the control and get an event and read the value of the hyperlinks when such a link is clicked. HTML is a great rendering language and it seems to be a waste if we could not use this technology in applications.
If this is not possible are there any good alternatives, as the WPF controls are not 'fluid' enough. I require a very flexible rendering environment but prefer not to reinvent the wheel.
I like to clarify that of course I can include such a control and get and send data using HPPT or other protocols but in my case I want to directly assign a string of HTML and capture the click on hyperlink events.
You can host any Windows Forms control in a WindowsFormHost (you'll probably find it in the toolbox.
However, FlowDocument maybe more suitable for such things, as it's truly WPF, so it can be the content of any control.
You could use the WebBrowser control to render your application's UI. I would advise against it. Versions of the controls could influence the way your application renders and it's going to be a hasle to mantain all the resources used in the UI (html, pics, javascript?)
Read a bit more on WPF, Expression Blend 3 was just released and you can make an awesome UI with it. To keep it fluid don't go crazy on things like transparency, it slows down loading times. WPF is a far more future proof technique.

Categories