WPF 根据按钮动态跳转窗体
XMAL文件中,用Tag保存要跳的页面
<Button Name="btnWindow01" Content="ClickMe" Width="100" Height="30" Click="btnNavigate_Click" Tag="SubWindow01"></Button>
<Button Name="btnWindow02" Content="ClickMe" Width="100" Height="30" Click="btnNavigate_Click" Tag="SubWindow02"></Button>
private void btnNavigate_Click(object sender, RoutedEventArgs e)
{
Type type = this.GetType();
Assembly assembly = type.Assembly;
Window win = assembly.CreateInstance(type.Namespace + "." + (sender as Button).Tag) as Window;
win.Show();
// or
win.ShowDialog();
}