using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
namespace WpfApplication1
{
public class NavigateTheWeb : Window {
Frame frm;
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new NavigateTheWeb());
}
public NavigateTheWeb()
{
Title = "Navigate the Web";
frm = new Frame();
Content = frm;
Loaded+= OnWindowsLoaded;
}
void OnWindowsLoaded(object sender,RoutedEventArgs args)
{
UriDialog dlg = new UriDialog();
dlg.Owner = this;
dlg.Text = "http://";
dlg.ShowDialog();
try {
frm.Source = new Uri(dlg.Text);
}
catch(Exception exc){
MessageBox.Show(exc.Message,Title);
}
}
}
public class UriDialog : Window
{
TextBox txtbox;
public UriDialog() {
Title = " enter a uri";
ShowInTaskbar = false;
SizeToContent = SizeToContent.WidthAndHeight;
WindowStyle = WindowStyle.ToolWindow;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
txtbox = new TextBox();
txtbox.Margin = new Thickness(48);
Content = txtbox;
txtbox.Focus();
}
public string Text {
set {
txtbox.Text = value;
txtbox.SelectionStart = txtbox.Text.Length;
}
get {
return txtbox.Text;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key==Key.Enter)
{
Close();
}
}
}
}