开发者

WPF trigger code behind button to display second form

I am a WPF novice.

开发者_StackOverflow中文版

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#?


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜