0

Problem is this annoying flashing:

enter image description here

Yes, I know this has been answer before, but none of the answers work for me except making the button non Focusable (Focusable = false), which is not something I intend to do.

I tried setting the "FocusVisualStyle" to null, both in template, both in the specific button. Didn't work.

I have the following (based on) style for buttons:

<SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/>
<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/>
<SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/>
<SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/>
<SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/>
<SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/>
<SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
<SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/>
<SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
    <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> <!- tried x:Null, tried removing alltogether -->
    <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
    <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Padding" Value="1"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                    <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsDefaulted" Value="true">
                        <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/>
                        <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="true">
                        <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/>
                        <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
                        <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/>
                        <Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I set style for window:

<Style TargetType="Button" BasedOn="{StaticResource ButtonStyle1}"/>

I have the following button:

<Button FontSize="18" Margin="5" Background="{StaticResource JITB.SolidColors.Open}" IsEnabled="{Binding IsEnabledSelected}" Command="{Binding DoOpenBackupFile}" Height="40">
    <DockPanel >
        <TextBlock Style="{StaticResource CustomFont}" Text="S " Foreground="White" Margin="0,-6,0,0"></TextBlock>
        <TextBlock Margin="0" DockPanel.Dock="Top" Text="{x:Static p:Resources.MWTab2OpenBtn}" Foreground="White" VerticalAlignment="Center"/>
    </DockPanel>
</Button>

(I tried setting "FocusVisualStyle" to null also in the dockpanel... )

Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66
  • 1
    Do you want a flashing button or you don't want that it's flashing? I'd suggest always demonstrate the issue with screenshot (animated gifs are the best, using e.g. [screentogif](http://www.screentogif.com/)) if you can't prepare [mcve](https://stackoverflow.com/help/mcve) – Sinatr Nov 09 '17 at 12:55
  • How to stop the flashing on windows 7 – Maverick Meerkat Nov 09 '17 at 13:41
  • @Sinatr added gif – Maverick Meerkat Nov 09 '17 at 13:47
  • 1
    I can't reproduce the issue on Window 10 and VM with Windows 7. The xaml is not complete, so I had to substitute some resources with constants and use `x:Null` instead of `FocusVisual`. – Sinatr Nov 09 '17 at 14:03
  • @Sinatr that's very easily reproduced with and without setting FocusVisualStyle... I geuss maybe you changed your theme in windows 7? I'm talking about the default Windows7 Aero theme – Maverick Meerkat Nov 09 '17 at 14:11
  • You can just copy paste this to any window, and test on windows 7 with default aero theme : - Both button 1 and 2,3 will have the flashing – Maverick Meerkat Nov 09 '17 at 14:13
  • 1
    I can't reproduce your issue too (win7). There's something in your resources somewhere that overrides your style. – dymanoid Nov 09 '17 at 15:48
  • @dymanoid can't be - I opened a completely new WPF project with regular button (check comment above) and nothing else. Still happens. Changing FocusVisualStyle - doesn't affect it at all... :-( – Maverick Meerkat Nov 09 '17 at 16:05
  • @dymanoid ok now I see that if I edit the template in the new project and disable the FocusVisualStyle there - it works ! So maybe you're right and in my real project something is overwriting it... I need to check. Thanks for the lead! – Maverick Meerkat Nov 09 '17 at 16:10
  • @dymanoid yeah you're right - if I set the style manually on the button - it works. I guess if I do "BasedOn" - it's being overwritten... – Maverick Meerkat Nov 09 '17 at 16:15
  • oh no, I see now that I had another trigger closer to the Button which was causing the problem and I forgot about. Sorry... – Maverick Meerkat Nov 09 '17 at 16:18

0 Answers0