tags:

views:

667

answers:

1

In a data entry form (Silverlight 3) I have one combo box whose selection can be changed when the user changes another - imagine a State list being repopulated depending on Country selection.

I want to highlight the change in this combo box with a simple glowing halo effect - basically a border that fades in then out again. I've created this simply using a Storyboard and Rectangle behind the control, but am sure there must be a better way of doing it - ideally something reusable.

Here's what I have:

<Rectangle x:Name="canvas" Height="24" Margin="98,58,79,0" 
    VerticalAlignment="Top" Width="169" Fill="#763DE4E4" 
    Canvas.ZIndex="1" Opacity="0" RadiusX="5" RadiusY="5"/>

<controls:ChildWindow.Resources>
    <Storyboard x:Name="HighlightControl">
        <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="canvas" 
            Storyboard.TargetProperty="(UIElement.Opacity)" From="0" To="1" 
            AutoReverse="True" Duration="0:0:1" />
    </Storyboard>
</controls:ChildWindow.Resources>

To use this effect on more than one control I currently have to reposition the rectangle and reset the Storyboard, or maintain a whole bunch of the rectangles and retarget the Storyboard.

I considered using a Border control and adding it to the control but this causes the Combo to move to accomodate the border - it needs to stay still with the halo glowing around it.

Update: It appears that the Blur effect can do the visible effect bit, which is fine - this is nicer than a side-by-side rectangle, so I'm just missing the reusable effect + animation bit. I wonder if this is what Behaviours are for?

+1  A: 

Have you ever tried using a dropshadow with a bright color like this?

 <ComboBox x:Name="comboBox" Margin="248,47,272,0" VerticalAlignment="Top">
  <ComboBox.Effect>
   <DropShadowEffect BlurRadius="100" ShadowDepth="0" Color="White"/>
  </ComboBox.Effect>
 </ComboBox>

Then animating the dropshadow with a storyboard or visual state?

Paully
Thanks the drop shadow also provides a good look, but does have the disadvantage that each control can only have a single Effect being applied at once - it also means that you drop out of accelerated graphics mode IIRC. The bit that's really still missing though is the reusable storyboard part - something where I can apply a single thing to a control and set it going.
Simon Steele