J'ai essayé cela juste pour voir ce qui va se passer et ça a marché mais je ne sais pas pourquoi. Quelqu'un peut-il m'expliquer ce qui se passe dans le fond de DependencyProperties
?DependencyProperty Strange Behavior
J'ai une classe qui déclare une DependencyProperty
mais dans une autre classe que je cible que DependencyProperty
en utilisant GetValue
et SetValue
.
est un exemple:
public class DependencyProperties : DependencyObject
{
public Size EstimatedSize
{
get { return (Size)GetValue(EstimatedSizeProperty); }
set { SetValue(EstimatedSizeProperty, value); }
}
public static readonly DependencyProperty EstimatedSizeProperty =
DependencyProperty.Register("EstimatedSize", typeof(Size), typeof(DependencyProperties), null);
}
public class MyControl: ContentControl
{
public Size CalculatedSize
{
get { return (Size)GetValue(DependencyProperties.EstimatedSizeProperty); }
set { SetValue(DependencyProperties.EstimatedSizeProperty, value); }
}
protected override OnApplyTemplate()
{
// This works but why? How is it possible to do this? What is happening under the hood?
this.CalculatedSize = new Size(123, 123);
}
}
Pourquoi est-il possible de le faire? Que se passe-t-il en arrière-plan de cet exemple? La classe MyControl n'a pas enregistré le DP mais il peut l'utiliser. Quelqu'un peut-il me dire ce qui se passe sous le capot?
Duplicata possible: http://stackoverflow.com/questions/6843877/difference-between-attached-and-non-attached-dependency-properties-in-silverligh – Blachshma