从另一个用户控件WPF访问一个用户控件 [英] Access a User Control from another User control WPF

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

问题描述

大家好,
我有一个用户控件,现在我想添加另一个用户控件)(此用户控件中的标签,并且还希望从另一个窗口(不是用户控件)访问它

如何在WPF中迷失方向

在此先感谢

Hello All,
I have a user control,now I want to add another user control)(tab in this user control and also want to access it from another window(not a user control )

how to do it kind of a lost in WPF

thanks in advance

推荐答案

您可以添加一个保存内部UserControl的属性.
You can add a property that holds the inner UserControl.


以另一种形式访问控件是不好的做法.如果您坚持要这样做,只需将控件公开(默认情况下,它是受保护的或私有的).

另外,用户控件内部的控件也不是公共的,因此您可能还需要更改其访问级别.

还有许多其他更正确的方法来获取另一种表单控件的数据/属性,其中一种是全局静态类,该类由设置/获取该类中属性的其他对象(即表单)操纵,或包含要访问的控件的表单内部的对象,这些对象将公开那些控件的值.
Accessing a control in another form is bad practice. If you insist on doing so, simply make the control public (by default, it''s either protected or private).

Also, controls INSIDE the user control are also not public, so you may need to change their access level as well.

There are many other more correct ways to get to the data/properties of another form''s control, one of which being a global static class that is manipulated by other objects (namely, forms) that set/get properties within that class, or an object internal to the form that contains the controls you want access to that exposes those controls'' values.


这篇关于从另一个用户控件WPF访问一个用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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