0
我有一個從System.Windows.Controls.Label派生的ExtendedLabel。 我想爲PaddingProperty提供默認值。 我知道我可以爲此使用OverrideMetadata方法。 但有些如何不起作用,填充 vallue仍然顯示爲5,5,5,5(這是標籤的默認值)。給PaddingProperty默認值不會改變
然而,一切正常預期的其他性能如保證金。
class ExtendedLabel : Label
{
static ExtendedLabel()
{
PaddingProperty.OverrideMetadata(typeof(ExtendedLabel), new FrameworkPropertyMetadata(new Thickness(0)));
MarginProperty.OverrideMetadata(typeof(ExtendedLabel), new FrameworkPropertyMetadata(new Thickness(0, 10, 0, 20)));
}
public ExtendedLabel()
{
// this.Padding = new Thickness(0);
}
}
PS: 我不希望在我的構造函數來設置填充。 因爲這避免了其他開發人員從其樣式中更改填充值。
非常感謝。 工作就像一個魅力.. –