Issue with binding Collection type of dependency property in style
I have a customcontrol exposing a Dependency property of type ObservableCollection. When i bind this properrty directly as part ofthe control's mark up in hte containing control everythihng works f开发者_如何学编程ine
<temp:EnhancedTextBox
CollectionProperty="{Binding Path=MyCollection, Mode=TwoWay}"/>
But when i try to do the binding in the style created for the control it fails,
<Style x:Key="abc2"
TargetType="{x:Type temp:EnhancedTextBox}" >
<Setter Property="CollectionProperty"
Value="{Binding Path=MyCollection, Mode=TwoWay}"/>
</Style>
Please help !!!!!
Thanks
It has to do with your data context for the style. There is no way for the style to know where MyCollection is coming from because although you may have it defined in the same file, the style does not share the data context.
I would also ask the question as to why you are setting the property in the style? The style is not meant for this sort of operation. The style is supposed to control the look of the UI element not provide the functionality.
精彩评论