如何在UserControl中将控件设为私有? [英] How do I make my controls inside a UserControl private?

查看:76
本文介绍了如何在UserControl中将控件设为私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有ComboBox和TextBox的用户控件。一切工作正常,除了我注意到从用户控件的实例对象中,我可以访问这两个控件。除非通过我自己的公开属性,否则不应访问它们。

I have a user control with a ComboBox and a TextBox. Everything is working great except I noticed that from my user control's instance object, I can access those two controls. They shouldn't be accessible except via my own exposed properties.

推荐答案

您可以使用 x:FieldModifier属性在控件上,因此:

You can use the x:FieldModifier attribute on your controls, thusly:

<TextBox x:Name="textBox1" x:FieldModifier="private" />

有趣的是,x:FieldModifier的MSDN页面没有将 private作为有效值属性,但我已经对其进行了测试,并且可以使用。

Interestingly the MSDN page for x:FieldModifier doesn't give "private" as a valid value for the attribute, but I've tested it and it works.

这篇关于如何在UserControl中将控件设为私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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