繁体   English   中英

C#WPF - TextBox没有显示字符

[英]C# WPF - TextBox is not showing the characters

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

对不起,如果我的英语不好,我是巴西人,我使用谷歌翻译。

您的Template不包含任何显示Text元素。 您需要添加名为PART_ContentHost ScrollViewer

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

TextBox样式和模板

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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