Use text box in another page to edit code of a button? - c#

I'm creating a web browser. On the "mainpage" it has a button that takes you to the homepage, i'd like to give the user the option of changing the home page on "page1" (settings). on page1 I have "textBox1"(where the user enter desired homepage) and "button1" (set). Could you help me set this up? Is there a way where doing that action can change the source of webBrowser1?

First I would suggest you to download this Programming Windows Phone 7 ebook and explore it to learn Windows phone programming before asking StackOverflow.
Coming to your question,
Create a Settings class in the project and Add a static string property named something like "HomePageUri". Then in your Page1, add the source uri to that "HomePageUri".
Then in your main page, in the OnNavigatedTo event update the WebBrowser's source or you can bind the WebBrowser's source directly to the "HomePageUri" property
Good luck

Related

How to reload or refresh a Windowsphone User Control in c#?

I am making a windowsphone silverlight App for windowsphone OS 8. I am Using windowsphone user controls where I make changes dynamically.
My question is just like the way we create an instance of a phoneApplication Page for Normal .xaml Page using NavigationService.Navigate("Source Uri with unique GUID") . How can I achieve the same effect for a windowsphone User Control Page where I make my dynamic changes to update as there is no Navigation Service.Navigate() method available. ?
Currently I have to Navigate like UserControl-Page-UserControl
When you want to Navigate from a page, you can use NavigationService.Navigate().
When you want to Navigate from a UserControl, You can use the PhoneApplicationFrame to navigate.
Code Sample:
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/MyProjectName;component/MyFolderName/MyPage.xaml", UriKind.Relative));
You need to append a GUID when you want to navigate to a new instance of the same page which you are currently residing.

Navigation between pages in WP8.1

I'm trying to migrate my app from WP8 to WP8.1. And I don't get how to navigate to already opened page with another parameters.
For example, I'm showing user info on UserPage giving it user's id as parameter. And when page is already is the content of the Frame I want to open UserPage again but for other user giving it another id.
My problem is that, using NavigationCacheMode set to Required for UserPage means that there will be no navigation with other parameters. But when NavigationCacheMode is set to Disabled navigation with another parameter is success but when I press back button old instance of UserPage is using data from new one.
In WP8 passing new parameters was enough to create new instance of a page with it's own cache. How to do similar in WP8.1 using WRT APIs?
Thanks to Romansz for the tip about using UserControl. Using UserControl binding to a ContentControl and handling BackKeyPress solves my problem with navigation.

How to show a hyperlink in a text

I have a text which may contain some special characters like <b></b> or a link. I want the user to be able to click on the link and open it. TextBlock or RichTextBox seems doesn't show links in a proper way:
<RichTextBox >
<Paragraph>
click here: http://www.google.com
</Paragraph>
</RichTextBox>
How can I show a text like that in a page?
Update: seems my question isn't clear. I ask a server for content and it returns back to me something like this:
from <b><i><a href="http://www.google.com" rel=nofollow> lorem ipsom
NPR:

 tapped in front of you probably know Bill Gates...
I want to show this in a WINDOWS PHONE page. TextBlock doesn't render it well. how can I show it human readable?
The way to solve your problem I see in using of WebBrowser control.
Then, accordingly to the article, you should go with Javascript to manage the links clicking etc (unless you want the links would be opened automatically with standard logic of Windows Phone):
Script is disabled in the WebBrowser control by default. Set the
IsScriptEnabled property to true if you want to enable scripting in
your control. You can then call scripts using the InvokeScript method.
The ScriptNotify event occurs when JavaScript in the WebBrowser
control passes a string to managed code.
That's a bit tricky way, but if you want to go any other way, you would have to implement your own parser of the code and build the sentence with labels and custom hyperlinks (as in provided above suggestions from comments).

How to get page name with webBrowser

Try to code with WPF. Currently I want to implement a simple webBrowser, and now I'm stuck. I want to get name of opened page (Every tab has name according to opened page), but I can't find the solution. In C# I can use this code:
TabControl.SelectedTab.Text = webBrowser.Url.Host.ToString();
But with WPF it doesn't work.
What is solution to find page name with WPF?
Please try like this,
TabControl.SelectedTab.Text = webBrowser1.Url.AbsoluteUri;

How to display a website only in the default browser

I'm currently having an issue after a click on an hyperlink inside a wpf Page.In my RequestNavigate or Click (both have the same behavior in this situation) event I do the usual Process.Start(hyperlink.NavigateURI).The problem is that this event opens the webpage both in the default browser (the behavior I'm looking for) and in my wpf Page object as well which I don't want.I was wondering if there was any workaround for this issue? Thanks in advance.
You need to set e.Handled = true to say you have already handled the hyperlink
See Example using Hyperlink in WPF
The reason your current page also loads with the Url is because you are using a Hyperlink. Try using either a Hyperlink with no Url, a button or a styled Label

Categories