Reputation: 91
I have a rather interesting case with ComboBox control - CustomComboBox;
In the style of this ComboBox, Popup contains one custom control that requests a DataContext;
<ctrl:CustomGrid DataContext="{TemplateBinding DataContext}" GridName="{Binding Preferences.CurrentGridName}"/>
The idea:
The logic:
The problem:
I am sure that something on the bindings or the presentation logic is bad... Please throw some thoughts on, I would appreciate a hint here
Thanks
Upvotes: 0
Views: 614
Reputation: 7661
OnApplyTemplate
is called when a ControlTemplate
is applied to the control that overrides the method (neither its parent, nor children). If OnApplyTemplate
is entered once, the overriding control must also be created once. I mean you simply have a single masterpage instance. This shouldn't be unexpected.
Speaking about Popup
s and DataContext
, there often are issues with bindings from a Popup
to outside it. So, I would rather write some code-behind to deliver correct context to Popup
s, instead of relying on Binding
s. There sure is a problem of DataContextChanged event absence prior to SL5. To workaround this one, you should define your custom DependencyProperty
on your CustomComboBox
, bind it to the CustomComboBox
's context and assign its value to the Popup
in the PropertyChangedCallback
.
Upvotes: 1