you're right CompositeCollection has no concept of datacontext , so it cannot inherit it from its parent.
from MSDN:
CompositeCollection can contain items such as strings, objects, XML nodes, elements, as well as other collections. An ItemsControl uses the data in the CompositeCollection to generate its content according to its ItemTemplate. For more information about using ItemsControl objects to bind to collections, see the Binding to Collections section of the Data Binding Overview.
to your question
But how is that working? it sets the source to something, but that something, in this case a CollectionViewSource uses a DataContext (as its not explicitly setting a source).
I think you think that Collection DependecyProperty can bind to any type of IEnumerable , so it doesn't matter how the collection was created while it was created and implemented by IEnumerable .
in your case, CVS inherits the DataContext from the window, and then binds to Items .
with regard to your second example, this does not work, because the ContentPesenter needs a dataContext to work, since it can inherit it, the binding mechanism simply sets itself as a dataContext, even if you tried to bind the Source content to the button, you forgot to set the path, I think, that is why he was ignored. all you have to do to get it working is just to install it like this:
<ContentPresenter Content="{Binding Source={StaticResource menu}, Path=Content}"/
makc
source share