我似乎无法让我的两个按钮在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