views:

68

answers:

1

Hi, 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 fine

<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

+1  A: 

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.

Craig Suchanec
Hi Will,Thanks for your reply. I did think of that but then if we assume that the style is not getting the data contet and hence the property is not used then how come the Property is being accessed?While debugging i noticed that if i removed the binding in the style the break point in the property's getter is never hit. But if i do use the binding for the property in the style the break point is hit.
Zepher
Also let me mention all properties like Text/toolTip etc works fine when binded thorugh style or anyhow.
Zepher
When you say the property is being accessed do you mean the CollectionProperty or the MyCollection property and what are you binding to the Text, ToolTip, etc when you are binding to those?
Craig Suchanec
Hi,When i say 'the property is being accessed' i mean the MyCollection. The CollectionProperty being a DP it is accessed implicitly.I am binding some string property from the same object which contains the MyCollection property .ThanksZepher
Zepher