Reputation: 10713
I have multiple styles in my applications. Here's the one this question is about:
<Style x:Key="RoundCornerSmart" TargetType="{x:Type vk:SmartButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type vk:SmartButton}">
<Border CornerRadius="8" BorderBrush="#006AB6" BorderThickness="1" Name="border">
<Grid x:Name="grid">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="border">
<Setter.Value>
LightGray
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="False">
<Setter Property="Background" TargetName="border">
<Setter.Value>
White
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="18" />
<Setter Property="Height" Value="62" />
<Setter Property="Width" Value="62" />
<Setter Property="Margin" Value="10" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="BorderBrush" Value="Black" />
</Style>
SmartButton is a class which extends the Button class, it's a Button user-control.
<vk:SmartButton HoldCommand="{Binding Path=ClickCommand}" EnableClickHold="True" MillisecondsToWait="1000" x:Name="key_U" Content="U" Grid.Column="8" Style="{DynamicResource RoundCornerSmart}"/>
When the smart button isn't pressed - its background is white, which is how it's supposed to be. However, when it's pressed, the background doesn't change. It's still white. What am I doing wrong? Why is the IsPressed not triggered?
EDIT:
When I comment the OnPreviewMouseLeftButtonDown method, it works.
Here's what happens in that method:
if (EnableClickHold)
{
Timer = new DispatcherTimer(DispatcherPriority.Normal, this.Dispatcher)
{
Interval = TimeSpan.FromMilliseconds(MillisecondsToWait)
};
Timer.Tick += Timer_Tick;
Timer.IsEnabled = true;
Timer.Start();
e.Handled = true;
}
Upvotes: 0
Views: 242
Reputation: 10713
The problem was:
e.Handled=true;
That line in the OnPreviewMouseLeftButtonDown method. I don't know why though. When I commented it, the background was set to LightGrey, it worked.
Upvotes: 1