Getting html to display in xaml - c#

I have tried phone:Webbrowser which does not automatically size to the required amount.
I have tried many textbox and richttextbox property extension libraries, I cannot get any to work.
I want to know how people get html into textboxes or richtextboxes in windows phone 8.
Argh, I have spent 2 evenings on this now! doh!
Context:
I am calling an API that is returning html (why oh god why)... I want to bind the returned html to a textbox or richtextbox or if I haveeee to, a phone:webbrowser.
Textbox and richtextbox do not support html.
phone:webbrowser does not adjust its height according to what's inside the document. You can supposedly do it by enabling javascript and calling window.external.Notify() but I couldn't get it to work quite right...
Moving on from the above problem, even if I did get the phone:webbrowser to work, if for test purposes I make the width 500 and height 500, I can see my html string as plain text rather than the webcontrol correctly parsing html... doh!

Just try this way.
your xaml:
<Grid x:Name="ContentGrid" Grid.Row="1">
<phone:WebBrowser HorizontalAlignment="Left" Margin="20,50,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="500" Width="430" />
</Grid>
in your code:
public MainPage()
{
InitializeComponent();
webBrowser1.Loaded += WebBrowser_OnLoaded;
}
private void WebBrowser_OnLoaded(object sender, RoutedEventArgs e)
{
webBrowser1.Navigate(new Uri("readme.htm", UriKind.Relative));
}
Hope it helps

Related

WebBrowser in a StackPanel does not expand to its content size in WPF

I have to display multiple HTML contents on a single window. These data come as strings. Every string represents one HTML file data.
I am using webbrowser control and stackpanel layout to display them on a single window.
<Grid >
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Background="YellowGreen">
<WebBrowser Margin="5" Loaded="WebBrowser_Loaded"/>
<WebBrowser Margin="5" Loaded="WebBrowser_Loaded" />
<WebBrowser Margin="5" Loaded="WebBrowser_Loaded" />
</StackPanel>
</ScrollViewer>
private void WebBrowser_Loaded(object sender, RoutedEventArgs e)
{
WebBrowser web = sender as WebBrowser;
web.NavigateToString(VM.HtmlContent);
}
Problem: Webbrowser is not rendered to its content size.
Regardless of the actual content size, all webbrowsers take same amount of space in the stack panel.
Current Output Screenshot
Web browsers 2nd and 3rd have not taken the required amount of space to render the content.
It seems the Webbrowser control is not giving the right information about its content size to the stack panel.
Given that, web browsers get rendered to its content size, I would like to avoid the scroll bar at the web browser level.
Any help is highly appreciated. Thank you.
WebBrowser control does not support this functionality. However you can get the content size and resize controls manually as demonstrated in this thread: https://stackoverflow.com/a/40795036/12797700

Is it possible to bind XAML/C# with HTML using PHP?

So I have a XAML button:
<StackPanel>
<TextBlock HorizontalAlignment="Left" Text="{Binding Version, ElementName=Control}" />
<Button Content="Support" Width="100" Click="HelpSupport_Click" />
</StackPanel>
Which links to some C#
private void HelpSupport_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("support.html");
}
Which takes a user to a webpage.
In my XAML StackPanel above I'm binding the software version into a text block for the user to see. But my question is, is it possible that when the user clicks the button to go to the website, can I somehow bind the text block data to be transferred into the HTML too? So that when the user gets to the webpage the software version is also showing there too? Just wondering if this would be done via PHP or a JSON call
I don't have a lot of recent experience with HTML and PHP, but if my memory doesn't fail me, you could add the text of the TextBlock as a variable at the end of the URL of the webpage (it would look like this www.webpage.com?text=version) and then from PHP use the GET method to get the value of the variable text in your URL.
You can do this with more than one variable, like this www.webpage.com?text=version&var2=hello
Managed to get it, these are the changes made:
private void HelpSupport_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("support.php?version=" + HttpUtility.UrlEncode(Version.ToString()));
}
Which put the number in the URL. So my output in HTML:
<textarea type="text" class="form-control" name="es_version" >
<?php echo $_GET["version"]; ?>
</textarea>

How do resize a Webbrowser in Windows Phone 8 App

I just try to simulate a resizing event of a webbrowser. It's because some user who are older and are not able to read that good see the conten in a bigger size. Following a simple version of the code:
<Viewbox x:Name="BrowserView" Stretch="None" >
<phone:WebBrowser Source="www.google.ch" x:Name="Minibrowser" IsScriptEnabled="True" height="644" Width="462" >
</phone:WebBrowser>
</Viewbox>
<Button Content="Resize" Click="Resize" />
Xaml.Code
And in the underlying code file a method which just resizes the webbrowser:
private void Resize(object sender, RoutedEventArgs e)
{
Minibrowser.Width = 800;
Minibrowser.Height = 1400;}
What happens is that the browser is resized. However it's not possible to scroll over the whole content because the webbrowser size is now bigger than the viewbox and screen as well.
Thanks a lot for help and I'm open to listen to other solutions
Have a look at this post about managing the browser-viewport and WP7 WebBrowser control zoom.
Plus, you could also look for "accessibility"...

loading pic in xaml web browser.

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:WebBrowser x:Name="browser" IsScriptEnabled="True" Margin="-12,0,-11,0" />
</Grid>
I initialized web browser using this code. Since, my html content is too big, it takes much more to load those html files. Till the html files displayed, web browser is being white color.
It makes me irritate. I need to know can we have any loader pic in web browser. So, the pic displayed until web browser loads the html files ???
I can't verify this at the moment but the approach I would take is to display an image via Image or some alternative, such as a loading message in XAML, and set the initial visibility of this stand-in to visible and the WebBrowser to collapsed.
Implement an event handler for the LoadCompleted event on the WebBrowser and when it is triggered, swap the visibility states to hide the progress/wait message and show the web browser.
It'll look roughly like:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Text="Loading... please wait" Visibility="Visibile" x:Name="loadingMessage"/>
<phone:WebBrowser x:Name="browser" IsScriptEnabled="True" Margin="-12,0,-11,0" LoadCompleted="htmlLoadCompleted" Visibility="Collapsed"/>
</Grid>
// In the code behind - HTML finished loading, swap visibility to show the page
private void htmlLoadCompleted(object sender, NavigationEventArgs e)
{
loadingMessage.Visibility = Visibility.Collapsed;
browser.Visibility = Visibility.Visibile;
}
I have concerns over when/how the WebBrowser starts loading, which is why I'd like to caution I don't have a local environment configured to verify this approach is 100% working. You might need to experiment with this some to get it working but I hope this helps set you on the right path.

How do always display the Numeric keyboard in windows phone 8?

I'm working on windows phone 8 app, I had a page which inputs number for that I gave code like this,
<TextBox Name="txtNumber" Height="Auto" Margin="0,10,0,510" >
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Number" />
</InputScope>
</TextBox.InputScope>
</TextBox>
by the above code; It display the numeric keyboard when I place the cursor to type; But I need a fixed keyboard which is always visible and if we type it has to enter the value to the textbox.
Would somebody please tell me how to do that.
Try this on for size:
Xaml:
<Grid
x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0"
Loaded="ContentPanel_Loaded">
<TextBox
Name="TB1"
HorizontalAlignment="Left"
Height="72"
Margin="0,74,0,0"
VerticalAlignment="Top"
Width="456"
InputScope="Number"/>
</Grid>
Code:
private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
{
// Turn on Tab Stops. You can set this in XAML as well.
this.IsTabStop = true;
// Set focus on the TextBox.
TB1.Focus();
}
It will spark up the SIP as it enters the <TextBox> ready for input. Hope it's what your looking for.
Got it from this MSDN blog.
The easiest way would probably be with creating your own user control. However it is most likely a lot of work to get it to work as a normal keyboard.
http://www.silverlightshow.net/items/Creating-a-Silverlight-Custom-Control-The-Basics.aspx
Or maybe perhaps this will help http://www.silverlightshow.net/items/Windows-Phone-7-Creating-Custom-Keyboard.aspx

Categories

Resources