如何将WPF表单发送到库函数? [英] How do I send a WPF form to a library function?

查看:98
本文介绍了如何将WPF表单发送到库函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决下面的问题。如何将以下代码从Winforms复制到WPF?



我在MyLibrary Static Class中有这个函数,我打算从WPF表单的析构函数中调用它。 br />


1.如何实现该功能?

2.如何调用该功能?



功能:

Can some one please help me on the below. How do I replicate the below code from Winforms to WPF ?

I have this function in MyLibrary Static Class which I aim to call it from the destructor of WPF form.

1. How do I implement the function?
2. How do I call the function?

Function:

public static void EmptyFields(Control parent)
        {
            try
            {
                foreach (Control c in parent.Controls)
                {


                    if (c.GetType() == typeof(TextBox))
                    {
                        ((TextBox)(c)).Text = string.Empty;
                    }

                    if (c.GetType() == typeof(ComboBox))
                    {
                        ((ComboBox)(c)).Text = string.Empty;
                    }

                    if (c.GetType() == typeof(CheckBox))
                    {
                        ((CheckBox)(c)).Checked = false;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                //System write e.Message;


            }

        }





来电:







Calling:


OpSupLib.EmptyFields(this);

推荐答案

请参阅我对问题的评论,以及以防万一,解决方案1.



现在,唯一真正需要建议的点是处理特定于WPF的异常的一种方法。我在最近的回答中详细解释了这一点: currentDomain.UnhandledExcepti ... [ ^ ]。



此外,你必须学习一般的例外情况。您应该停止在太多地方处理异常,应该停止在本地处理它们,等等。也许我过去的一些答案可以帮助你:

C#构造函数中的异常原因来电者分配失败? [ ^ ],

操作系统中存储.net异常的位置 [ ^ ],

异常详细信息:System.Runtime.InteropServices.COMException:使用CLSID {0006F03A-0000-0000-C000-00000检索组件的COM类工厂0000046}由于以下错误而失败:... [ ^ ],

处理类库(dll)中的异常 [ ^ ],顺便说一下,
,以防万一,表格异常:收集例外情况 [ ^ ],

错误记录和屏幕截图。 [ ^ ]。



除此之外,大多数您的代码非常非常类似于WPF。请尽量自己做其余的事情,只有在遇到一些真正的困难时才问一些问题。



-SA
Please see my comments to the question and, just in case, to Solution 1.

Now, the only point which really needs advice is a way of handling exceptions specific to WPF. I explained it in detail in my recent answer: currentDomain.UnhandledExcepti...[^].

Besides, you have to learn exceptions in general. You should stop handling exceptions in too many places, should stop handling them locally, and so on. Perhaps some of my past answers can help you:
Does Exception in C# Constructor Cause Caller Assignment to Fail?[^],
where was stored .net exceptions in operating system[^],
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error:...[^],
Handling exceptions in class library (dll)[^],
by the way, just in case, on exceptions with Forms: Catching an Exception[^],
Error Logging and Screen Shot.[^].

Other than then, most of your code is very, very similar to WPF. Please try to do the rest by yourself, ask some questions only if you face some real difficulty.

—SA


这篇关于如何将WPF表单发送到库函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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