Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows;
- using System.Windows.Input;
- namespace WpfTutorialSamples.Misc_controls
- {
- public partial class WebBrowserControlSample : Window
- {
- public WebBrowserControlSample()
- {
- InitializeComponent();
- wbSample.Navigate("http://www.wpf-tutorial.com");
- }
- private void txtUrl_KeyUp(object sender, KeyEventArgs e)
- {
- if(e.Key == Key.Enter)
- wbSample.Navigate(txtUrl.Text);
- }
- private void wbSample_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
- {
- txtUrl.Text = e.Uri.OriginalString;
- }
- private void BrowseBack_CanExecute(object sender, CanExecuteRoutedEventArgs e)
- {
- e.CanExecute = ((wbSample != null) && (wbSample.CanGoBack));
- }
- private void BrowseBack_Executed(object sender, ExecutedRoutedEventArgs e)
- {
- wbSample.GoBack();
- }
- private void BrowseForward_CanExecute(object sender, CanExecuteRoutedEventArgs e)
- {
- e.CanExecute = ((wbSample != null) && (wbSample.CanGoForward));
- }
- private void BrowseForward_Executed(object sender, ExecutedRoutedEventArgs e)
- {
- wbSample.GoForward();
- }
- private void GoToPage_CanExecute(object sender, CanExecuteRoutedEventArgs e)
- {
- e.CanExecute = true;
- }
- private void GoToPage_Executed(object sender, ExecutedRoutedEventArgs e)
- {
- wbSample.Navigate(txtUrl.Text);
- }
- }
- }
- <Window x:Class="WpfTutorialSamples.Misc_controls.WebBrowserControlSample"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="WebBrowserControlSample" Height="1080" Width="1920">
- <Window.CommandBindings>
- <CommandBinding Command="NavigationCommands.BrowseBack" CanExecute="BrowseBack_CanExecute" Executed="BrowseBack_Executed" />
- <CommandBinding Command="NavigationCommands.BrowseForward" CanExecute="BrowseForward_CanExecute" Executed="BrowseForward_Executed" />
- <CommandBinding Command="NavigationCommands.GoToPage" CanExecute="GoToPage_CanExecute" Executed="GoToPage_Executed" />
- </Window.CommandBindings>
- <DockPanel>
- <ToolBar DockPanel.Dock="Top">
- <Button Command="NavigationCommands.BrowseBack">
- <Rectangle Width="16" Height="16" />
- </Button>
- <Button Command="NavigationCommands.BrowseForward">
- <Rectangle Width="16" Height="16" />
- </Button>
- <Separator />
- <TextBox Name="txtUrl" Width="300" KeyUp="txtUrl_KeyUp" />
- <Button Command="NavigationCommands.GoToPage">
- <Rectangle Width="16" Height="16" />
- </Button>
- </ToolBar>
- <WebBrowser Name="wbSample" Navigating="wbSample_Navigating"></WebBrowser>
- </DockPanel>
- </Window>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement