1
我爲我的文本框創建了一個樣式,並且爲了給它定製邊框,我決定用其ControlTemplate
進行磨練,但是當我運行該項目時,光標似乎並未顯示在文本框中,爲什麼是這樣,我該如何解決它?WPF:Styled TextBox Not Showing Cursor
我的風格的代碼如下
<Style x:Key="PrimaryTextBox" TargetType="{x:Type TextBox}">
<Setter Property="BorderBrush" Value="#FFBAC7DC"/>
<Setter Property="MinHeight" Value="30"/>
<Setter Property="MinWidth" Value="40"/>
<Setter Property="BorderBrush" Value="#FF07172B"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border CornerRadius="3" Padding="4"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter Content="{TemplateBinding Text}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
及其實施
<TextBox Style="{StaticResource PrimaryTextBox}"/>
如果在沒有首先設置ControlTemplate的情況下發生此問題,情況如何? (像這裏的一個:https://stackoverflow.com/q/41319889/997940) –