1
我有這個Dynamic Resource
設置我TextBox
的風格:WPF - 文本框樣式仍然默認設置時觸發火災
<Style x:Key="TextBoxStyle" TargetType="TextBox">
<Setter Property="FontSize" Value="30"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="FontFamily" Value="CenturyGothicRegual"/>
<Setter Property="Foreground" Value="#FF5B5B5B"/>
<Setter Property="Opacity" Value="1"/>
<Setter Property="BorderBrush" Value="#FF5B5B5B"/>
<!--<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style x:Name="ActiveStyle" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="Black"/>
</Style>
</Setter.Value>
</Setter>-->
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="10"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="Pink" />
<Setter Property="BorderThickness" Value="15"/>
</Trigger>
</Style.Triggers>
</Style>
而且使用它的文本框:
<TextBox Grid.Row="2" Grid.Column="1" Margin="2,2,2,2" Style="{DynamicResource TextBoxStyle}"
FontSize="30" Text="asdasd" HorizontalContentAlignment="Left" VerticalContentAlignment="Center"
FocusVisualStyle="{StaticResource TextBoxStyle}">
</TextBox>
同樣的問題當我將鼠標懸停在鼠標上或單擊文本框時,邊框將獲得默認的藍色。 然而 borderthickness 確實改變時,我設置它們(醜陋的方式,但需要調試)。那麼如何解決這個問題呢?
它有點工作,但現在當我點擊文本框內部,發生以下異常: **在PresentationFramework.dll中發生類型爲「System.InvalidOperationException」的異常,但未在用戶代碼中處理 附加信息:「{DependencyProperty.UnsetValue}」和「BorderBrush」屬性的值無效。 如果有這種異常的處理程序,程序可能會安全地繼續。** – agiro
起初我忘了翻譯異常抱歉。我現在編輯過,只有部分英文。 – agiro
它有一個'BorderBrush' setter,它就在模板之前。 ' '這是線。 我錯過了什麼嗎? –
agiro