Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Input;
  4.  
  5. namespace WpfTutorialSamples.Misc_controls
  6. {
  7. public partial class WebBrowserControlSample : Window
  8. {
  9. public WebBrowserControlSample()
  10. {
  11. InitializeComponent();
  12. wbSample.Navigate("http://www.wpf-tutorial.com");
  13. }
  14.  
  15. private void txtUrl_KeyUp(object sender, KeyEventArgs e)
  16. {
  17. if(e.Key == Key.Enter)
  18. wbSample.Navigate(txtUrl.Text);
  19. }
  20.  
  21. private void wbSample_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
  22. {
  23. txtUrl.Text = e.Uri.OriginalString;
  24. }
  25.  
  26. private void BrowseBack_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  27. {
  28. e.CanExecute = ((wbSample != null) && (wbSample.CanGoBack));
  29. }
  30.  
  31. private void BrowseBack_Executed(object sender, ExecutedRoutedEventArgs e)
  32. {
  33. wbSample.GoBack();
  34. }
  35.  
  36. private void BrowseForward_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  37. {
  38. e.CanExecute = ((wbSample != null) && (wbSample.CanGoForward));
  39. }
  40.  
  41. private void BrowseForward_Executed(object sender, ExecutedRoutedEventArgs e)
  42. {
  43. wbSample.GoForward();
  44. }
  45.  
  46. private void GoToPage_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  47. {
  48. e.CanExecute = true;
  49. }
  50.  
  51. private void GoToPage_Executed(object sender, ExecutedRoutedEventArgs e)
  52. {
  53. wbSample.Navigate(txtUrl.Text);
  54. }
  55.  
  56. }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. <Window x:Class="WpfTutorialSamples.Misc_controls.WebBrowserControlSample"
  71. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  72. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  73. Title="WebBrowserControlSample" Height="1080" Width="1920">
  74. <Window.CommandBindings>
  75. <CommandBinding Command="NavigationCommands.BrowseBack" CanExecute="BrowseBack_CanExecute" Executed="BrowseBack_Executed" />
  76. <CommandBinding Command="NavigationCommands.BrowseForward" CanExecute="BrowseForward_CanExecute" Executed="BrowseForward_Executed" />
  77. <CommandBinding Command="NavigationCommands.GoToPage" CanExecute="GoToPage_CanExecute" Executed="GoToPage_Executed" />
  78. </Window.CommandBindings>
  79. <DockPanel>
  80. <ToolBar DockPanel.Dock="Top">
  81. <Button Command="NavigationCommands.BrowseBack">
  82. <Rectangle Width="16" Height="16" />
  83. </Button>
  84. <Button Command="NavigationCommands.BrowseForward">
  85. <Rectangle Width="16" Height="16" />
  86. </Button>
  87. <Separator />
  88. <TextBox Name="txtUrl" Width="300" KeyUp="txtUrl_KeyUp" />
  89. <Button Command="NavigationCommands.GoToPage">
  90. <Rectangle Width="16" Height="16" />
  91. </Button>
  92. </ToolBar>
  93. <WebBrowser Name="wbSample" Navigating="wbSample_Navigating"></WebBrowser>
  94. </DockPanel>
  95. </Window>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement