我打破了文本框 [英] I broke the textbox

查看:152
本文介绍了我打破了文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个WPF形式(从几天前的winform移动),我想定制我的文本框。我得到的文本框的行为我怎么想,但现在我不能给它输入,当我点击它,它根本不响应。我想我把它弄坏了,反正这里是我的代码:

I am making a wpf form(moved from winform a couple days ago), and i wanted to customize my textbox. I got the textbox to behave how i want it to, but now i cant give it input, and it does not respond at all when i click it. I think i broke it, anyways here is my code:

<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="10,48,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" Foreground="White">
        <TextBox.Style>
            <Style TargetType="{x:Type TextBox}">
                <Setter Property="BorderBrush" Value="#FF497AB4"/>
                <Setter Property="Background" Value="#FF2E2E2E"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TextBox}">
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="BorderBrush" Value="OrangeRed"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TextBox.Style>
    </TextBox>



那么,我做错了什么? !谢谢

So what am i doing wrong? Thanks!

推荐答案

尝试添加的ScrollViewer到您的模板,像这样的:

Try adding a Scrollviewer to your template, like this:

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

您已经有了一些示例模板的这里

You've got some example templates here

的问题是,模板没有一个ContentHost,所以它不会呈现的内容。要添加ContentHost,你应该添加一个名为的PART_ContentHost的元素的解释为的这里

The problem was that the template didn't have a ContentHost, so it would not render the contents. To add a ContentHost, you should add an element named "PART_ContentHost" as explained here

这篇关于我打破了文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆