Я определил два свойства DependencyProperties:
public int TempProp1
{
get { return (int)GetValue(TempProp1Property); }
set { SetValue(TempProp1Property, value); }
}
// Using a DependencyProperty as the backing store for TempProp1. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TempProp1Property =
DependencyProperty.Register("TempProp1", typeof(int), typeof(CustomControl1), new PropertyMetadata(200));
второй:
public int TempProp2
{
get { return (int)GetValue(TempProp2Property); }
set { SetValue(TempProp2Property, value); }
}
// Using a DependencyProperty as the backing store for TempProp2. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TempProp2Property =
DependencyProperty.Register("TempProp2", typeof(int), typeof(CustomControl1), new PropertyMetadata(10, OnTempProp2Changed));
private static void OnTempProp2Changed(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
CustomControl1 cc = o as CustomControl1;
if (cc == null) return;
cc.TempProp1 = (((int)(e.NewValue)) / 2);
}
Обратите внимание, что в OnTempProp2Changed () я задаю значениеon свойство TempProp1 .
Проблема: TempProp1 значение не отражено в XAML.
Я хочу добиться сериализации TempProp1 в XAML, даже если его значение установлено из другого DependencyProperty ( TempProp2 ).Это делается в пользовательском элементе управления Silverlight, и между этими двумя DependencyProperties нет привязок или каких-либо других специфических вещей.