Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 防止按钮在WPF中闪烁_C#_Wpf_Windows_Xaml_Button - Fatal编程技术网

C# 防止按钮在WPF中闪烁

C# 防止按钮在WPF中闪烁,c#,wpf,windows,xaml,button,C#,Wpf,Windows,Xaml,Button,我已经创建了一个WPF应用程序。这必须有一个红色的主题。所以我将每种颜色都设置为红色,但问题是当窗口打开时,窗口中的所有按钮都开始闪烁。有趣的是,它们同时开始,但过了一段时间,它们开始分化。当窗体失去焦点时,它们都停止闪烁。单击按钮时,只有该按钮保持闪烁。但当not按钮控件获得焦点时,它们都会再次开始闪烁 我发现它可能与Focusable属性有关,但改变它并不会改变任何东西。我还找到了一种覆盖默认样式的方法,但这并不能解决问题 这是我的XAML代码: <Grid x:Name="gServ

我已经创建了一个WPF应用程序。这必须有一个红色的主题。所以我将每种颜色都设置为红色,但问题是当窗口打开时,窗口中的所有按钮都开始闪烁。有趣的是,它们同时开始,但过了一段时间,它们开始分化。当窗体失去焦点时,它们都停止闪烁。单击按钮时,只有该按钮保持闪烁。但当not按钮控件获得焦点时,它们都会再次开始闪烁

我发现它可能与Focusable属性有关,但改变它并不会改变任何东西。我还找到了一种覆盖默认样式的方法,但这并不能解决问题

这是我的XAML代码:

<Grid x:Name="gServerSettings">
    <Label x:Name="lTitle" Content="Server Settings" HorizontalAlignment="Center" Margin="182,0,0,166" VerticalAlignment="Center" Width="118" Foreground="#FFFF9999" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="16" FontWeight="Bold" Height="34"/>
    <TextBox x:Name="tServer" Margin="72,39,10,0" TextWrapping="Wrap" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="0"/>
    <Label x:Name="lServer" Content="Server" HorizontalAlignment="Left" Margin="10,39,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" Height="24" VerticalContentAlignment="Center"/>
    <TextBox x:Name="tDatabase" Margin="72,68,10,0" TextWrapping="Wrap" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="1"/>
    <Label x:Name="lDatabase" Content="Database" HorizontalAlignment="Left" Margin="10,68,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" VerticalContentAlignment="Center" Height="24"/>
    <TextBox x:Name="tUsername" Margin="72,97,10,0" TextWrapping="Wrap" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="2"/>
    <Label x:Name="lUsername" Content="Username" HorizontalAlignment="Left" Margin="10,97,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" VerticalContentAlignment="Center" Height="24"/>
    <Label x:Name="lPassword" Content="Password" HorizontalAlignment="Left" Margin="10,126,0,0" VerticalAlignment="Top" Width="62" Foreground="#FFFF9999" VerticalContentAlignment="Center" Height="24"/>
    <PasswordBox x:Name="tPassword" Margin="72,126,10,0" Background="{x:Null}" Foreground="#FFFF9999" BorderBrush="#FFFF9999" SelectionBrush="#FFFF9999" BorderThickness="1" VerticalContentAlignment="Center" Height="24" VerticalAlignment="Top" TabIndex="3"/>
    <Button x:Name="bOK" Content="OK" HorizontalAlignment="Left" Margin="215,168,0,0" VerticalAlignment="Top" Width="75" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FFFF9999" BorderThickness="1" IsDefault="True" TabIndex="6"/>
    <Button x:Name="bCancel" Content="Cancel" HorizontalAlignment="Left" Margin="135,168,0,0" VerticalAlignment="Top" Width="75" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FFFF9999" BorderThickness="1" IsDefault="True" TabIndex="5"/>
    <Button x:Name="bTestConnection" Content="Test Connection" HorizontalAlignment="Left" Margin="10,168,0,0" VerticalAlignment="Top" Width="120" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FFFF9999" BorderThickness="1" IsDefault="True" TabIndex="4" IsHitTestVisible="False"/>
</Grid>
我还没有以编程方式执行任何操作,因此我的.CS文件是空的


有人知道如何解决这个问题吗?

基本上,你必须重新实现按钮样式并删除情节提要。您可以使用Expression Blend转储默认按钮样式,并根据自己的喜好对其进行修改。没有任何其他简单的方法可以禁用该情节提要。

它们开始闪烁,而用户没有进行任何交互?或者只在点击后?它们开始闪烁,没有任何交互。当窗口或非按钮控件具有焦点时,它们都会开始闪烁。在问题中查看我的编辑。。。