简体   繁体   中英

C# WPF - TextBox is not showing the characters

I was programming in C # WPF, I've customized the style of a text box, and now he's not sampling the characters.

<Window.Resources>
    <Style x:Key="wwindow" TargetType="{x:Type Window}">
        <Setter Property="BorderBrush" Value="Black"></Setter>
        <Setter Property="BorderThickness" Value="1"></Setter>
    </Style>
    <Style x:Key="textBoxx" TargetType="{x:Type TextBox}">
        <Setter Property="BorderBrush" Value="#FFBDC4D1"></Setter>
        <Setter Property="Background" Value="White"></Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Border CornerRadius="0" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" >

                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="Orange"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

Code of TextBox:

 <TextBox Style="{DynamicResource textBoxx}" x:Name="fala" HorizontalAlignment="Left" Height="32" Margin="81,118,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="177" VerticalContentAlignment="Center" SelectionBrush="#FFD6DBE9" IsEnabled="True" Cursor="IBeam" AcceptsReturn="True"/>

Sorry if my english is bad, i'm brazilian and i've used the Google Translate.

Your Template does not contain any element to display Text . You need to add ScrollViewer named PART_ContentHost :

<Border CornerRadius="0" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
    <ScrollViewer x:Name="PART_ContentHost"/>
</Border>

TextBox Styles and Templates

PART_ContentHost: A visual element that can contain a FrameworkElement. The text of the TextBox is displayed in this element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM