Styles are unexpectedly being set when window resizes
I have the following in a TreeViewItem header:
<StackPanel Orientation="Horizontal">
<Canvas Style="{Binding Converter={StaticResource StatusToCanvasStyle}}"
MouseDown="MetaContactButton_MouseDown" MouseUp="MetaContactButton_MouseUp"
MouseLeave="MetaContactButton_MouseLeave" Tag="{Binding}" />
<TextBlock Style="{Binding Path=Status, Converter={StaticResource StatusToTextStyle}}"
Margin="5,1" Text="{Binding Path=DisplayName}" Tag="{Binding}"
MouseDown="SMC_MouseDown" ContextMenu="{StaticResource MetaContactMenu}"
ContextMenuOpening="SMC_ContextMenuOpening" VerticalAlignment="Center">
<TextBlock.ToolTip>
<Binding Converter="{StaticResource CTTConverter}" />
</TextBlock.ToolTip>
</TextBlock>
</StackPanel>
The Style binding on the Canvas is pulled from a ResourceDictionary depending on a property of the bound item, and it serves to change the Background of the Canvas.
Now, the odd behavior:The Background color of the Canvas will change at random while the TreeView is resizing, and does not go back to the correct value until the TreeView's items are refreshed. This is not happening because the underlying data member is changing; in fact, the IValueConverter associated with the binding is not being called at all!
I've tried the following to fix it:
- Instead of setting a style containing the background, I tried setting the Background property directly through a binding. No change in behavior.
- Changed the Background brush being set from a RadialGrandientBrush to a SolidColorBrush. No change in behavior.
- Thought it might be the Background property causing a problem, tried setting a Background property on the TextBlock. The TextBlock's Background style was not reset during resize.
- Changed the Canvas to a TextBlock. No change in behavior.
- Switched the position of the Canvas and TextBlock to see if order made a difference. No change in behavior.

