WPF 触发按钮后面的代码以显示第二个表单
我是 WPF 新手。
我创建了一个包含组合框的表单,用于选择多字段键值(从 XML 数据文件填充)。
我还创建了第二个 WPF 表单,可用于显示与从第一个表单中选择的多字段键值关联的记录中的所有字段值。
我需要能够单击一个按钮,这将导致显示第二个表单,并填写与所选关键字段值关联的所有字段。
如何使用 C# 编写这样的事件触发器?
I am a WPF novice.
I have created a form containing a combo box with which to choose a multi-field key value(populated from an XML data file).
I have also created a second WPF form which is available to display all field values from the record associated with the multi-field key value chosen from the first form.
I need to be able to click a button which will cause the second form to be displayed, with all fields filled in which are associated with the chosen key field values.
How do I go about writing such an event trigger using C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几个步骤(顺便说一句,这并不是真正的 MVVM)...
首先,向按钮添加一个点击处理程序
其次,在点击处理程序代码中,实例化您的新表单
第三,为新表单设置数据上下文等
第四,通过在 xaml 中调用 .Show() 显示新表单,
向相关按钮添加单击处理程序...
在 Visual Studio 中,您可以右键单击 click="" 中的文本,然后选择导航到处理程序和 Visual Studio 将为您生成代码。
在你的点击处理程序中,在代码后面,做这样的事情......
couple of steps (this is not really MVVM, BTW) ...
first, add a click handler to your button
second, in the click handler code, instantiate your new form
third, set the data context, etc for the new form
forth, show the new form by calling .Show()
in your xaml add a click handler to the button in question....
in visual studio, you can right click the text in the click="" and choose to navigate to the handler and visual studio will generate the code for it for you.
in your click handler, in code behind, do something like this....