类似于Excel的行为WPF文本框 [英] excel-like behaviour wpf textbox

查看:153
本文介绍了类似于Excel的行为WPF文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建电子邮件文本框至极的文字结合的一个整数(如:123456789),但它显示了千位分隔符(如123.456.789),但是当我选择要编辑它没有分隔字符串返回文本框,直到失去文本框焦点,就像在Excel中。任何建议?谢谢!

I want to create e textbox wich text binds an integer (e.g 123456789) but it shows the thousand separator (eg 123.456.789), but when I select the textbox for editing it the string returns without separator, until the textbox loses the focus, just like in excel. Any advice? thank you!

推荐答案

使用触发器如果未选中文本框哪些格式值

Use a Trigger which formats the value if the TextBox isn't selected

<Style TargetType="{x:Type TextBox}">
    <Setter Property="Text" Value="{Binding SomeValue, StringFormat=N2}" />
    <Style.Triggers>
        <Trigger Property="IsKeyboardFocusWithin" Value="True">
            <Setter Property="Text" Value="{Binding SomeValue}" />
        </Trigger>
    </Style.Triggers>
</Style>

您还可以使用一个转换器进行格式化,如果你不能轻易使用的StringFormat格式化

You can also use a Converter for formatting if you can't easily format with StringFormat

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

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