So, I want to create an Uri from user input.
I have a textbox, an Ok button and web browser control.
User writes his desired web address, clicks button and launches getUri method.
I tried to create something like this:
private void ok_tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Uri address = new Uri(AdressBox.Text, UriKind.Absolute);
web.Navigate(address);
}
Aaand it works quite allright. However, only when user types adress with “http://”. Problem is: no one writes whole links, and with just “google.com” app crashes.
i could check if there is something like “http” in user input and add it manually… but it feels like I try to reinvent the wheel.
Use the
UriBuilderclass. Its String constructor defaults toHTTPprotocol: