Styles are unexpectedly being set when window resizes

This is a very strange problem that some users of my application have been having for months, through the Feb. CTP and into May. I was unable to diagnose it until I started experiencing it myself yesterday...and I'm still unable to diagnose it.

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:

  1. Instead of setting a style containing the background, I tried setting the Background property directly through a binding. No change in behavior.
  2. Changed the Background brush being set from a RadialGrandientBrush to a SolidColorBrush. No change in behavior.
  3. 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.
  4. Changed the Canvas to a TextBlock. No change in behavior.
  5. Switched the position of the Canvas and TextBlock to see if order made a difference. No change in behavior.
Does anyone have any idea why this is happening, or have any other ideas for troubleshooting/fixing? If someone wants to try the application to see what's happening, its source is available via SVN at https://svn.bountysource.com/shaim/trunk/
[4269 byte] By [csammis] at [2007-12-21]

Visual Studio Orcas

Site Classified