我似乎無法讓我的兩個按鈕在Window2上成功更改我的主窗口上的webbrowser url。我想要做的就是點擊按鈕1並轉到一個地址,然後單擊另一個按鈕並轉到其他地址。 我已經嘗試綁定沒有任何運氣,我已經嘗試將MainWindow webbrowser設置爲新的Uri,但是這也不起作用。我收到一個錯誤:'NullReferenceException未處理'「未將對象引用設置爲對象的實例。」WPF XAML兩個按鈕,在不同的窗口上更改webbrowser url
不知道我在做什麼錯,任何幫助將不勝感激。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Timers;
using System.Threading;
namespace _2CAMS
{
/// <summary>
/// Interaction logic for Window2.xaml
/// </summary>
///
public partial class Window2 : Window
{
MainWindow mw;
public Window2()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.ShowActivated = true;
this.MouseLeftButtonDown += delegate { this.DragMove(); };
}
private void Button1_Checked(object sender, RoutedEventArgs e)
{
}
private void button2_Click(object sender, RoutedEventArgs e)
{
this.Close();
Application.Current.Shutdown();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
//this.DragMove();
}
private void Image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Process.Start("http://www.website.com");
}
private void button3_Click(object sender, RoutedEventArgs e)
{
Application.Current.MainWindow.WindowState = System.Windows.WindowState.Minimized;
//App.Current.MainWindow.Hide();
Window3 win3 = new Window3();
win3.Show();
this.WindowState = System.Windows.WindowState.Minimized;
}
private void button4_Click(object sender, RoutedEventArgs e)
{
mw.webBrowser1.Navigate(new Uri("http://www.address1.com"));
}
private void button5_Click(object sender, RoutedEventArgs e)
{
mw.webBrowser1.Navigate(new Uri("http://www.address2.com"));
}
}
}
*那*代碼給你一個NRE?哪個變量是空的? – BradleyDotNET 2015-02-09 21:09:40
不確定,在查看「查看詳情...」時我沒有看到任何東西,或者我只是不知道我在找什麼。 – cheapkid1 2015-02-09 21:15:51
[快照](http://s42.photobucket.com/user/cheapkid1/media/c_zpsamhxjbwy.png.html) – cheapkid1 2015-02-09 21:26:38