WPF C# - 从usercontrol1更新按钮更新usercontrol2中的数据 [英] WPF C# - Updating data in usercontrol2 from usercontrol1 update button

查看:350
本文介绍了WPF C# - 从usercontrol1更新按钮更新usercontrol2中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello all



我有一个userControl,其中包含标签项内的其他userControl。通过与我的父userControl上的各种复选框进行交互,可以看到它们并清除它们。我有适用于父userControl的验证和writetodatabase函数。我需要做的是当点击uC1上的Update(利用CommandBinding)按钮时,其他选项卡上的所有相关uC数据也会保存到db。我已经得到验证工作,但我很难保存uC2 / uC3 / uC4等数据...任何指针都会受到欢迎。

PS我想保留我的uC'尽可能松散耦合......以及我是初学者和一步一步的指示会很棒。



提前致谢。

Hello all

I''ve got a userControl that houses other userControls within tab items. They are made visible and cleared by interaction with various checkbox''s on my parent userControl. I''ve validation and writetodatabase functions in place which works for parent userControl. What I need to have happen is when "Update" (utilizes CommandBinding) button on uC1 is clicked, that all relevant uC data on other tabs are saved to db as well. I''ve got validation to work but am stumped in saving the data of uC2/uC3/uC4 etc. ... any pointers would be most welcome.
PS I''m trying to keep my uC''s as loosely coupled as possible... as well as I''m a beginner and step by step instructions would be great.

Thanks in advance.

推荐答案

您是否查看了成员属性?您可以在dot net框架中执行的操作之一是创建自定义属性,然后使用该属性标记类成员。换句话说,您可以标记要在特定控件中保存的属性。一旦您标记了要保存的部分,父控件就可以遍历子控件集合并使用反射来获取使用自定义属性标记的属性。我曾写过一个* .ini文件阅读器编写器,它会以这种方式序列化和反序列化各种控件。
Have you looked into member attributes? One of the things you can do in the dot net framework, is create a custom attribute and then tag class members with that attribute. In other words, you can tag the properties you want to save within a specific control. Once you''ve tagged the parts you want to save, the parent control can loop through the collection of child controls and use reflection to get the properties that are tagged with your custom attribute. I once wrote a *.ini file reader writer that would serialize and deserialize various controls this way.


这篇关于WPF C# - 从usercontrol1更新按钮更新usercontrol2中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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