我有什麼一些可能看起來像一個簡單的問題,儘管我盡了最大努力,我一直無法「修復」這樣的問題:TextBox控件以及自定義樣式不點火的GotFocus
我有一個自定義樣式的文本框,在「通用」程序中定義;此樣式將覆蓋默認值,因此每次有人使用TextBox時都會使用該樣式。 問題是應用該樣式時,在GotFocus,IsKeyboardFocusWithinChanged在和PreviewGotKeyboardFocus事件-not-解僱任何更長的時間。 我已經驗證過,只有在應用此風格時纔會發生這種情況(如果我將其註釋掉並運行應用程序,則會正確觸發事件)。
所以我的問題基本上是,任何人都經歷了類似的話?如果是這樣,有沒有人知道這個問題的解決方案?
樣式如下(靜態資源的簡單SolidColorBrushes):
<Style TargetType="{x:Type TextBox}" x:Key="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="BorderBrush" Value="{StaticResource BrushBorder}"/>
<Setter Property="ContextMenu" Value="{StaticResource TextBoxContextMenu}" />
<Setter Property="Foreground" Value="{StaticResource BrushForeground}" />
<Setter Property="SelectionBrush" Value="{StaticResource BrushHighlight}" />
<Setter Property="Background" Value="{StaticResource BrushBackground}"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border BorderThickness="1" x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
<ScrollViewer x:Name="PART_ContentHost"
Margin="0" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="Background" Value="{StaticResource BrushLightBg}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource BrushMouseoverBackground}" />
</Trigger>
</Style.Triggers>
</Style>
所以你-are-得到我所提到的焦點事件?你到底在哪裏爲這些添加處理程序?我通過單獨的行爲類來添加它們,並且它們在沒有樣式的情況下工作得很好 - 但不符合樣式。 – t0yk4t 2014-09-02 12:26:33
@MelanieSchmidt將它們添加到那裏的惡意代碼中,不得不削減索姆角。但他們會在這裏開火。忘記將其粘貼在 – 2014-09-02 12:28:32
好吧,這真的很奇怪 - 他們現在的工作,我也...肯定只有一個僥倖...標記你的答案作爲解決方案,感謝您的時間! – t0yk4t 2014-09-02 12:31:42