如何在不同的框架中打开页面-WPF

如何在不同的框架中打开页面-WPF,wpf,frames,Wpf,Frames,我在WPF C#窗口中有两个框架。加载后,应用程序将页面加载到左侧框架中,而不会加载到右侧框架中。在左框中浏览了2页之后,我试图在右框中加载另一页。我能做到这一点的唯一方法是关闭窗口并重新加载 当在同一WPF窗口的左框中的不同页面上单击按钮时,如何在WPF窗口的右框中加载新页面而不重新加载孔窗口 多谢各位 编辑: 为了澄清一点,我有一个带有两帧的窗口。我想通过单击左框页面上的按钮打开右框页面。这就是我所拥有的: 持有“test”int的变量类: 主窗口: public MainWindo

我在WPF C#窗口中有两个框架。加载后,应用程序将页面加载到左侧框架中,而不会加载到右侧框架中。在左框中浏览了2页之后,我试图在右框中加载另一页。我能做到这一点的唯一方法是关闭窗口并重新加载

当在同一WPF窗口的左框中的不同页面上单击按钮时,如何在WPF窗口的右框中加载新页面而不重新加载孔窗口

多谢各位

编辑:

为了澄清一点,我有一个带有两帧的窗口。我想通过单击左框页面上的按钮打开右框页面。这就是我所拥有的:

持有“test”int的变量类:

主窗口:

    public MainWindow()
    {
        InitializeComponent();
        int mytest = variables.test;
        left1 left1 = new left1();
        left.NavigationService.Navigate(left1);
        Right1 right1 = new Right1();
        if (mytest == 1)
        {
            right.NavigationService.Navigate(right1);
            MessageBox.Show("1");
        }
    }
和左边的1页:

 public left1()
    {
        InitializeComponent();

    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        int test = 1;
        variables.test = test;
        MainWindow mw = new MainWindow();
        mw.Show();
    }

这可以工作,但它会打开另一个调用mw.Show()的窗口;有没有一种方法可以在不打开另一个窗口(如刷新窗口)的情况下工作?我尝试了mw.InitializeComponent();这将显示MessageBox,但不会重新呈现主窗口。我曾尝试在MainWindow中创建一个方法,并在left1页面上调用该方法,单击按钮,但它做了相同的事情。。。显示消息框,但不刷新主窗口。

如果您还没有弄清楚,请确定我是新的。。。很多年前,我学习了Basic、Pascal和C语言,然后在10年前做了一些web开发,但这已经是一段很长的时间了。我想出来了!!我与C#WPF只合作了大约两周

我将右框架的Visibility属性绑定到MainWindow类下的一个方法,该方法在单击按钮时调用,并在INotifyPropertyChanged事件中使用。这就是我现在拥有的:

MainWindow.xmal.cs:

    public class Refresh : INotifyPropertyChanged
{
    private string vis1;
    public string Vis1
    {
        get { return vis1; }
        set
        {
            if (vis1 != value)
            {
                vis1 = value;
                OnPropertyChanged("Vis1");
            }
        }
    }
    protected void OnPropertyChanged(string propertyname)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
}

public partial class MainWindow : Window
{
    private static Refresh Visi;
    public MainWindow()
    {
        InitializeComponent();
        Left1 l1 = new Left1();
        Right1 r1 = new Right1();
        left.NavigationService.Navigate(l1);
        right.NavigationService.Navigate(r1);
        Visi = new Refresh { Vis1 = "Hidden" };
        DataContext = Visi;
    } 
    public static void showRight()
    {
        Visi.Vis1 = "Visible";
    }
}
XAML:

<Frame x:Name="right" Content="Frame" HorizontalAlignment="Left" Height="224" Margin="262,10,0,0" VerticalAlignment="Top" Width="225" Visibility="{Binding Vis1}" />
希望这对其他人有帮助!我只花了一天半的时间就搞定了!哈哈,我的第一次成功绑定


因此,在这段代码中,右边的框架加载了一个页面,但从视图中隐藏,左边的框架页面显示出来。单击左侧页面上的按钮时,右侧框架将被取消隐藏

要通过ClickEvent事件在WPF中打开其他页面,必须初始化导航服务。让我们看看我的wpf应用程序代码:我打开第2页的按钮点击事件,该按钮出现在第1页:

private void Button_Click(object sender, RoutedEventArgs e)
{

    NavigationWindow _navigationWindow = new NavigationWindow();

    _navigationWindow.Height = this.Height;

    _navigationWindow.Width = this.Width;

    _navigationWindow.Show();

    _navigationWindow.Navigate(new Page2());

    this.Close();


}

检查这里看起来像相同的问题:也检查这个..谢谢你看这个。我在上面更新了我的情况。
    public partial class Left1 : Page
{
    public Left1()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        MainWindow.showRight();
    }
}
private void Button_Click(object sender, RoutedEventArgs e)
{

    NavigationWindow _navigationWindow = new NavigationWindow();

    _navigationWindow.Height = this.Height;

    _navigationWindow.Width = this.Width;

    _navigationWindow.Show();

    _navigationWindow.Navigate(new Page2());

    this.Close();


}
public void Login_Click(object sender, RoutedEventArgs e)
{

    NavigationWindow _navigationWindow = new NavigationWindow();

    _navigationWindow.Height = this.Height;

    _navigationWindow.Width = this.Width;

    _navigationWindow.Show();

    _navigationWindow.Navigate(new Page1());


    this.Close();
}