WPF中的手动页面加载
我的主窗口中有一个按钮,点击这个按钮,主窗口应该被重新加载。如何做到这一点 请回复 谢谢 沙拉斯WPF中的手动页面加载,wpf,Wpf,我的主窗口中有一个按钮,点击这个按钮,主窗口应该被重新加载。如何做到这一点 请回复 谢谢 沙拉斯 只需在按钮单击事件中重新加载:)或更详细地描述问题通过重新加载,您的意思是重新绘制?或者你的意思是完全摧毁并重新装载?什么?C#,VB?请更具体地说明你需要什么,这样人们就不需要浪费时间来访问它了。顺便说一句,你说请回复,所以请回复我有点困惑,为什么你想重新加载主窗口-你的意思是你想刷新它吗?如果是这样,我会使用数据绑定来管理它,只需刷新底层的ViewModel/模型(取决于是否使用MVVM)。
只需在按钮单击事件中重新加载:)或更详细地描述问题通过重新加载,您的意思是重新绘制?或者你的意思是完全摧毁并重新装载?什么?C#,VB?请更具体地说明你需要什么,这样人们就不需要浪费时间来访问它了。顺便说一句,你说请回复,所以请回复我有点困惑,为什么你想重新加载主窗口-你的意思是你想刷新它吗?如果是这样,我会使用数据绑定来管理它,只需刷新底层的ViewModel/模型(取决于是否使用MVVM)。
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
public Button button
{
get
{
return this.button1; //Expose the button.
}
}
}
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
this.MainWindow = new Window1(); //create the window
this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
((Window1)MainWindow).button1.Click += new RoutedEventHandler(button1_Click); //add a handler to that button
MainWindow.Show();
}
void button1_Click(object sender, RoutedEventArgs e)
{
this.MainWindow.Close(); //Is disposed
MainWindow = new Window1(); //recreate
this.MainWindow.Show(); //reload
}
}