I've written a simple recycling control factory that is used to create and recycle controls. The idea is simple: the factory takes Func function as a parameter in constructor. Also it has an internal stack of FrameworkElements for recycling. GetControl method of the factory is implemented in obvious way: if there is a control in the stack, return it. In the other case, create a new control.
Imaging a simple situation. My control is just
<Border BorderBrush="Black" BorderThickness="5" Width="100" Height="30"
Background="{Binding RelativeSource={RelativeSource AncestorType=StackPanel},
Path=Background}" />
There are two StackPanels with different backgrounds: the first is red, the second is green. I add a new control (using the factory) to the first stackpanel. It has a red background. I add a control to the second stackpanel. It has a green backgound. Then I remove the control from the first stackpanel. It's recycled. I add the control to the second StackPanel. But it has a red background! It seems that RelativeSource trigger wasn't updated.
Is the any way to handle the situation?