2009-04-19 4 views

답변

1

이 그렇지 않은 것을 증명 (또는 증명할 수) :

public class SomeObject 
{ } 

public class SomeAdorner : Adorner 
{ 
    public SomeAdorner(UIElement adornedElement) : base(adornedElement) 
    { 
     // comment out the following statement to see that, by default, an adorner does not 
     // take on the data context of its adorned ui element 
     SetBinding(
      DataContextProperty, 
      new Binding(DataContextProperty.Name) 
      { 
       Mode = BindingMode.OneWay, 
       Source = adornedElement 
      } 
     ); 
    } 

    protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
    { 
     base.OnPropertyChanged(e); 

     if ((e.Property.Name.Equals(DataContextProperty.Name)) && (e.NewValue is SomeObject)) 
     { MessageBox.Show("DataContext changed!"); } 
    } 
} 

public partial class Window1 : Window 
{ 
    public Window1() 
    { 
     InitializeComponent(); 
     Loaded += new RoutedEventHandler(Window1_Loaded); 
    } 

    void Window1_Loaded(object sender, RoutedEventArgs e) 
    { 
     AdornerLayer.GetAdornerLayer(WindowContentWithElementName) 
      .Add(new SomeAdorner(WindowContentWithElementName)); 

     WindowContentWithElementName.DataContext = new SomeObject(); 
    } 
} 
+2

내가 그것을 언급 할 가치가 있다고 생각의 Adorner가 AdornerDecorator의 DataContext를 사용중인 상속합니다. 따라서 다른 FrameworkElement 내부에 AdornerDecorator를 정의하면 표시되는 모든 adorners는 FrameworkElement와 동일한 DataContext를 갖게됩니다. – Lukazoid