C#WPF - TextBox没有显示字符

时间:2014-04-02 21:10:57

标签: c# wpf

我使用C#WPF进行编程,我已经自定义了文本框的样式,现在他没有对字符进行采样。

<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>

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"/>

对不起,如果我的英语不好,我是巴西人,我已经使用了Google翻译。

1 个答案:

答案 0 :(得分:2)

您的Template不包含要显示的任何元素Text。您需要添加名为ScrollViewer的{​​{1}}:

PART_ContentHost

TextBox Styles and Templates

  

PART_ContentHost:可以包含FrameworkElement的可视元素。 TextBox的文本显示在此元素中。