Hi,

I am templating a ToolBar control so that it looks like the Windows 7 explorer toolbar. I have a class ToolBar7 that inherits ToolBar and assigns its Style and ItemContainerStyle in the constructor:
csharp Code:
  1. public class ToolBar7 : ToolBar
  2.     {
  3.         public ToolBar7()
  4.         {
  5.             ToolBar.SetOverflowMode(this, OverflowMode.Never);
  6.             this.Style = (Style) Themes.ResourceFactory.Dictionary["ToolBarStyle"];
  7.             this.ItemContainerStyle = (Style) Themes.ResourceFactory.Dictionary["ToolBarButtonStyle"];
  8.         }
  9.     }
(The Themes.ResourceFactory class and its Dictionary property basically finds and returns the Generic.xaml resource dictionary in this custom control library).

The styles are this:
xml Code:
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  3.    
  4.     <ResourceDictionary.MergedDictionaries>
  5.         <ResourceDictionary Source="Brushes.xaml" />
  6.     </ResourceDictionary.MergedDictionaries>
  7.  
  8.     <Style TargetType="ToolBar" x:Key="ToolBarStyle">
  9.         <Setter Property="Template">
  10.             <Setter.Value>
  11.                 <ControlTemplate TargetType="ToolBar">
  12.  
  13.                     <Border Name="BottomBorder" BorderThickness="0,0,0,1"
  14.                             BorderBrush="{StaticResource ToolBarBottomBorder}" CornerRadius="0"
  15.                             SnapsToDevicePixels="True"
  16.                             Height="31">
  17.  
  18.                         <Border Name="OuterBorder" BorderThickness="0,1,0,1"
  19.                                 BorderBrush="{StaticResource ToolBarOuterBorder}" CornerRadius="0"
  20.                                 SnapsToDevicePixels="True">
  21.  
  22.                             <Border Name="InnerBorder" BorderThickness="1" BorderBrush="{StaticResource ToolBarBorder}"
  23.                                     CornerRadius="0" SnapsToDevicePixels="True"
  24.                                     Background="{StaticResource ToolBarBackground}">
  25.  
  26.                                 <ToolBarPanel x:Name="PART_ToolBarPanel" IsItemsHost="true" Margin="2" />
  27.  
  28.                             </Border>
  29.  
  30.                         </Border>
  31.                     </Border>
  32.  
  33.                 </ControlTemplate>
  34.             </Setter.Value>
  35.         </Setter>
  36.     </Style>
  37.  
  38.     <Style TargetType="Button" x:Key="ToolBarButtonStyle">
  39.         <Setter Property="Template">
  40.             <Setter.Value>
  41.                 <ControlTemplate TargetType="Button">
  42.  
  43.                     <Border Name="OuterBorder" BorderThickness="1" CornerRadius="3" SnapsToDevicePixels="True" Height="22">
  44.  
  45.                         <Border Name="InnerBorder" BorderThickness="1" CornerRadius="2" SnapsToDevicePixels="True">
  46.  
  47.                             <ContentPresenter Margin="12,0" />
  48.  
  49.                         </Border>
  50.  
  51.                     </Border>
  52.  
  53.                     <ControlTemplate.Triggers>
  54.                         <Trigger Property="IsMouseOver" Value="True">
  55.                             <Setter TargetName="OuterBorder" Property="Border.BorderBrush"
  56.                                     Value="{StaticResource ToolBarButtonBorder}" />
  57.                             <Setter TargetName="InnerBorder" Property="Border.BorderBrush"
  58.                                     Value="{StaticResource ToolBarButtonInnerBorder}" />
  59.                             <Setter TargetName="OuterBorder" Property="Border.Background"
  60.                                     Value="{StaticResource ToolBarButtonBackground}" />
  61.  
  62.                         </Trigger>
  63.                     </ControlTemplate.Triggers>
  64.                 </ControlTemplate>
  65.             </Setter.Value>
  66.         </Setter>
  67.     </Style>
  68.  
  69. </ResourceDictionary>

When I use a ToolBar7 on a window, I can see two strange behaviors:

1. Only the first button in the ToolBar is highlighted when the mouse hovers over it; the others just remain their default state. I don't see why this happens, I'm simply using a Trigger in the control template for the Button, why is it triggering for one button but not the others?

2. The button is only highlighted when I move the mouse over its text. Due to the margin of 12 on the left and right of the button, if I'm thinking correctly it should trigger as soon as the mouse moves into that '12 unit margin', but it doesn't. The strange this is: when I move the mouse away from the text, it DOES stay highlighted until I leave that '12 unit margin'... Strange

I tried to explain it with these screenshots (yes, I artificially pasted a mouse cursor in there )



Top image: mouse moves inside the button (yet not inside the text) but button is not highlighted.
Middle image: mouse moves over text (button is highlighted)
Bottom image: mouse moves away from text (yet still inside button) and button remains highlighted, even though it was not highlighted in the same position in the top image!

This might seem like a minor issue but it is actually really annoying, it feels as if the highlighting only works half the time and as if there's a slight lag before the highlighting.

Of course the first issue (only first button highlighting) is more important.



Any help with this? Thanks!