简体   繁体   English

对话框窗口更改主窗口

[英]Dialog Window Change the Main Window

how to make something like this:(Screen is not from my app) 如何制作这样的东西:(屏幕不是来自我的应用程序) 在此处输入图片说明
When is change the button in dialogBox, it automatically change the Bitmap in MainWindow... I hope you understand my prob ;d So how can i make this dialog window ? 当更改对话框中的按钮时,它将自动更改MainWindow中的位图...希望您理解我的问题; d那么我该如何创建此对话框窗口? Or how can i get access to Mainwindow variables from dialogWindow? 或者如何从dialogWindow访问Mainwindow变量?

If you have no architecture to support that (like MVVM ), you can simply use the Application object in you dialog code-behind: 如果您没有支持该结构的体系结构(例如MVVM ),则可以在对话框后面的代码中简单地使用Application对象:

MainWindow mainWindow = Application.Current.MainWindow as MainWindow;
mainWindow.button1.Content = "Dialog rename me";

Application object is set on your application execution and is global. Application对象在应用程序执行时设置,并且是全局的。

Define a class where you put all information relevant to your item. 定义一个类别,在其中放置与项目相关的所有信息。 All properties uses NotifyPropertyChanged. 所有属性都使用NotifyPropertyChanged。
One of this property is the Title. 此属性之一是标题。 So now in your main window you have a TextBlock bound your object title (it might be within a control that draws the object and write the title above), and when you click on a button it opens another window. 因此,现在在主窗口中,有一个TextBlock绑定了对象标题(它可能在绘制对象并在上面写标题的控件内),并且当您单击按钮时,它会打开另一个窗口。 In the constructor( new()) of the second window, you give the drawn object as argument. 在第二个窗口的constructor(new())中,将绘制的对象作为参数。
So when you change the title in the second window, it gets updated in the first. 因此,当您在第二个窗口中更改标题时,它会在第一个窗口中更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM