My application creates multiple windows which are always created, showed and hid/closed when some buttons are pressed. These buttons share this style:

<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
<Setter Property="ClickMode" Value="Press"></Setter>
<Setter Property="Template">
<ControlTemplate TargetType="{x:Type Button}">
<Rectangle x:Name="RctBtn" Fill="Blue"/>
<TextBlock Text="{TemplateBinding Content}"></TextBlock>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Fill" TargetName="RctBtn" Value="Red" />

My code looks like:

public Window1()
this.button1.AddHandler(Control.MouseDownEvent, new MouseButtonEventHandler(openWindow), true);
this.button2.AddHandler(Control.MouseDownEvent, new MouseButtonEventHandler(closeWindow), true);

private void openWindow (object sender, RoutedEventArgs e)
/* Here some code */
Window1 w1 = new Window1();


private void closeWindow (object sender, RoutedEventArgs e)

I want to launch this application in a PC with a touch screen, then I’m using MouseDown event instead of Click event.

I have realized that when these buttons are pressed, sometimes, they are not changed to Red. I tried to call Dispatcher.Invoke with Render priority once the button is pressed but it didn’t solve the problem.

Object.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
Application.Current.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

¿Could you help me?

Thank you in advance,