本文介绍了如何使用C#链接两个Wpf Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个WPF窗口,即 MainWindow Window1 。在 MainWindow 我有一个文本框( textbox1 )和一个按钮,在 Window1 中我有一个文本框( textbox2 ) 。



我想要完成的是当我点击按钮时, textbox1 中输入的内容现在显示在 textbox2中



我相信我的xaml对于两个窗口都是正确的,我在我的中添加了private void button_click_1 ..... MainWindow.cs 的。但是当我尝试输入动作时:



textbox2.Text = textbox1.Text;



它无法识别 textbox2





我是WPF的新手c#所以任何帮助将不胜感激。谢谢

I have two WPF windows, that is MainWindow and Window1. In MainWindow i have a textbox(textbox1) and a button, in Window1 i have a textbox(textbox2).

What i am trying to accomplish is that when i click the button, whatever is typed in textbox1 is now displayed in textbox2.

my xaml i believe is correct for both windows and i have added the "private void button_click_1....." in my MainWindow.cs. however when ever i try to type the action:

textbox2.Text = textbox1.Text;

it does not recognize textbox2


I am fairly new to WPF and c# so any assistance would be appreciated. Thanks

推荐答案


public void ShowWindow1Screen(Window1ViewModel window1ViewModel)
       {
           Window1= new Window1();
           Window1.DataContext = window1ViewModel)
           Window1.Owner = nicknameView;
           Window1.ShowDialog();
       }



然后。





创建NavigationService实例.cs类MainWindowViewModel文件。

然后


then.


Create instance of NavigationService.cs class MainWindowViewModel file.
then

Window1ViewModel window1ViewModel = new Vindow1ViewModel();
window1ViewModel.Name = MainWindowTextValue;
NavigationService navigationService = new NavigationService();
navigationService.ShowWindow1Screen(window1ViewModel);


这篇关于如何使用C#链接两个Wpf Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 23:34