Hello,

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">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle x:Name="RctBtn" Fill="Blue"/>
<TextBlock Text="{TemplateBinding Content}"></TextBlock>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Fill" TargetName="RctBtn" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

My code looks like:

public Window1()
{
InitializeComponent();
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();

W1.ShowDialog();
}

private void closeWindow (object sender, RoutedEventArgs e)
{
This.Close();
}

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,

iBenzal