2010-12-21 18 views
1

好,我想建立一個WP7控制,所以我把它寫,所有順利,但問題是,我可以寫(見onItemsSourcePropertyChanged),但不是在讀書,我想解釋一下攔截更好:wp7和依賴屬性:onChanged和onRead?

public static readonly 
DependencyProperty ItemsSourceProperty= 
     DependencyProperty.Register(
      "ItemsSource", 
      typeof(ObservableCollection<ObjWithDesc>), 
      typeof(HorizontalListBox), 
      new PropertyMetadata(OnItemsSourcePropertyChanged) 
     ); 




    static void OnItemsSourcePropertyChanged(DependencyObject obj,DependencyPropertyChangedEventArgs e) 
{ 
     ((HorizontalListBox) obj).OnItemsSourcePropertyChanged(e); 
} 

OnItemsSourcePropertyChanged在我使用SetValue(dp,..)時調用,但沒有onItemsSourcePropertyRead?當我使用GetValue()時被調用?感謝

回答

0

你可以只添加OnRead行動,以支持字段的吸氣:

public string ItemsSource 
    { 
     get 
     { 
      // Call your OnRead functionality here! 
      return (string)GetValue(ItemsSourceProperty); 
     } 

     set 
     { 
      SetValue(ItemsSourceProperty, value); 
     } 
    } 
+0

但它使用XAML就像 LXG 2010-12-23 14:01:38

+0

@ user233150您可以發佈?一個你想要做什麼的完整例子 – 2010-12-23 14:54:46