public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(MyClass), new PropertyMetadata(string.Empty));
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
В этой части вы устанавливаете значение по умолчанию:
new PropertyMetadata(string.Empty)
всегда будет начинаться с пустой строки.
EDIT:
Ну, я действительно хочу решить это. Я подумал, что решение не кажется самым правильным, поскольку мы можем попытаться улучшить его вместе.
Сделай это в своем базовом классе:
public virtual void DefineDefaultValue(object default)
{
defaultValue = default;
OnPropertyChanged("MyProperty");
}
static object defaultValue;
public static object Define()
{
return defaultValue;
}
public int MyProperty
{
get { return (int)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(int), typeof(MainMenuBase), new PropertyMetadata((int)Define()));
В конце концов, сделайте это в конструкторе вашего класса:
public void ClassConstructor()
{
DefineDefaultValue("BlaBlaBla");
}
public override void DefineDefaultValue(object default)
{
base.DefineDefaultValue(default);
}