WPF 触发按钮后面的代码以显示第二个表单

发布于 2024-10-06 22:38:18 字数 204 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事与诗 2024-10-13 22:38:18

几个步骤(顺便说一句,这并不是真正的 MVVM)...
首先,向按钮添加一个点击处理程序
其次,在点击处理程序代码中,实例化您的新表单
第三,为新表单设置数据上下文等
第四,通过在 xaml 中调用 .Show() 显示新表单,

向相关按钮添加单击处理程序...

<Button Click="myClickHandler"/>

在 Visual Studio 中,您可以右键单击 click="" 中的文本,然后选择导航到处理程序和 Visual Studio 将为您生成代码。

在你的点击处理程序中,在代码后面,做这样的事情......

public void myClickHandler(object sender,EventArgs)
{
    MySecondForm form = new MySecondForm();
    form.DataContext = theDataContextIWantToSet;
    form.Show();
}

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....

<Button Click="myClickHandler"/>

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....

public void myClickHandler(object sender,EventArgs)
{
    MySecondForm form = new MySecondForm();
    form.DataContext = theDataContextIWantToSet;
    form.Show();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文