Applying Generic Style on UIElement

Oct 14, 2009 at 11:03 AM

Hi Guys,

I want to apply a generic event setter style to a UIElement's GotFocus but it doesnt apply to the only textbox on my UI.

This way...

 

<Window x:Class="Window4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:self="clr-namespace:TestGrid"
Title="Window4" Height="300" Width="300">

<Window.Resources>
    <Style TargetType="{x:Type UIElement}">
       <EventSetter Event="GotFocus" Handler="UIElementFocus"/>
       <Style.Triggers>
         <Trigger Property="IsFocused" Value="True">
           <Setter Property="UIElement.Opacity" Value="70"/>
         </Trigger>
      </Style.Triggers> 
   </Style>
</Window.Resources>

<StackPanel Orientation="Vertical">
<TextBox Text="Put Focus On Me Please!"/>
</StackPanel> 
</Window>

I am expecting the style to apply all the UI elements on the current window. (The trigger for opacity is just an extra check if whether the UIElement I have focused becomes opaque)

 

But it seems not to be happening. UIElementFocus event handler is not getting called. 

Am I missing something here?

Thx
Vinit Sankhe