2015-07-10 110 views
0

我創建了一個WPF應用程序。這必須有一個紅色的主題。所以我將每種顏色都設置爲紅色,但問題是窗口內的所有按鈕在窗口打開時開始閃爍。有趣的是他們同時開始,但過了一段時間他們開始分歧。當表單失去焦點時,它們都停止閃爍。單擊按鈕時,只有該按鈕保持閃爍。但是當一個「不按鈕」控件獲得焦點時,它們都會再次開始閃爍。防止WPF中閃爍的按鈕


我發現它可能不得不用Focusable屬性做一些事情,但改變它並不會改變任何東西。我還找到了一種覆蓋默認樣式的方法,但這並不能解決問題以太。 Source

這是我的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文件是空的。

Normal Blinking

是否有人知道如何解決這個問題?

+0

他們開始閃爍沒有來自用戶的任何交互?或者只有在他們被點擊後? – user469104

+0

他們開始閃爍沒有任何交互。當窗口或「未按鈕」控件具有焦點時,它們開始閃爍。在問題中查看我的編輯... –

回答

0

你將不得不基本上重新實現按鈕樣式並刪除故事板。您可以使用Expression Blend轉儲出默認的按鈕樣式,並根據自己的喜好進行修改。沒有任何其他簡單的方法來禁用故事板。