我已經創建了一個將它作爲基類來處理某些功能的類。現在我想擴大這個班級的工作。但是這裏有一些我不希望被用戶顯示的屬性。所以問題是如何隱藏一些依賴屬性。如何從子類中隱藏DependencyPropery?
我知道BrowsableAttribute
但我不能在我的基類中使用它,因爲這被其他類使用。所以我只想隱藏新擴展類中的一些屬性。
public class BaseControl : Control
{
static BaseControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(BaseControl), new FrameworkPropertyMetadata(typeof(BaseControl)));
}
public int BaseProperty
{
get { return (int)GetValue(BasePropertyProperty); }
set { SetValue(BasePropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for BaseProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BasePropertyProperty =
DependencyProperty.Register("BaseProperty", typeof(int), typeof(BaseControl), new UIPropertyMetadata(100));
}
public class Child1Control : BaseControl
{
// Using BaseProperty for internal Uses.
}
public class Child2Control : BaseControl
{
//TODO: How To HIDE the BasePropery here so that
}
如果用戶使用基類,用戶是否應該能夠訪問該屬性? – 2013-03-18 15:08:59
沒有那個屬性需要完全隱藏。 – JSJ 2013-03-18 15:09:51
很難說沒有一個例子,但爲什麼不把它們設置爲「私人」? – 2013-03-18 15:11:18