从WPF应用返回值 [英] Return Value from WPF App

查看:405
本文介绍了从WPF应用返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我不得不处理VBA程序中出现的问题.它不是在Excel或Office的任何版本中,而是在另一个环境中.为了增强安全性,Microsoft不断破坏VBA使用的常用对话框和其他ActiveX控件.

Recently I have had to deal with things breaking in a VBA program. It is not in Excel or anything Office but in another environment. To strengthen security Microsoft keeps breaking commonly used dialogs and other ActiveX controls used by VBA.

现在大多数时候我都在C#/WPF中工作.我想在WPF中制作一些控件和对话框.我可以毫无问题地将参数从VBA传递到WPF.如何制作可以返回值的WPF应用.

Mostly now I work in C#/WPF.  I want to make some of the controls and dialogs in WPF.  I can pass parameters from VBA to WPF with no problem.  How can I make a WPF app that will return a value.

我怀疑某个地方有类似这样的好例子.大概是5到10年前完成的.在过去的几周中,我尝试了许多不同的搜索键,但似乎找不到.

I suspect that somewhere there is a good example of something like this.  Probably done 5 to 10 years ago.  I have tried many different search keys over the last couple of weeks but cannot seem to find one.

推荐答案

为应用程序添加处理程序退出.

Add a handler for the Application.Exit.

然后在处理程序中

private void Application_Exit(object sender, ExitEventArgs e)
{
    e.ApplicationExitCode = 99;
}

其中99是要返回的代码.

where 99 is the code you want to return.


这篇关于从WPF应用返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆