If you look at Selector and TabItem classes they apparently both own the IsSelectedProperty.
static Selector()
{
...
IsSelectedProperty = DependencyProperty.RegisterAttached("IsSelected", typeof(bool), typeof(Selector), ...);
...
}
static TabItem()
{
IsSelectedProperty = Selector.IsSelectedProperty.AddOwner(typeof(TabItem), ...);
...
}
So I guess my question is… since the Tabitem contains the actual propertychanged logic, what is the point of the IsSelectedProperty even residing in the Selector class?
In this specific case,
Selectorhas theIsSelectedDP because there are a number of controls that derive from it whose items can be selected (ComboBox,ListBox,ListView,TabControl,DataGrid). They all need an ability to mark an item withIsSelected, therefore that DP is declared in their common base class. Like Tim said, DRY.Another reason that
TabItemadds itself as an owner is that in theSelectorclass,IsSelectedis an attached property because you can have just about anything as an item in aSelector. Attached properties are pretty mobile that way.However,
TabItemadds itself as an owner such that it is not an attached property onTabItem. It also registers a callback method to be called when the value changes so that it can do a few things when selected or unselected.And yes, it is easier to type
<TabItemand seeIsSelectedin Intellisense rather than going, “But how the heck do I make one selected?” and have to hunt around and find that you need to use an attached property from some other class.