日期时间格式到 WPF 文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26161425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:35:05  来源:igfitidea点击:

DateTime format to a WPF TextBox

c#wpfdatetime

提问by Tom026

I need some help.

我需要帮助。

  1. My problem is,I have a textbox,I wanna write a correct DateTime form for it with "autostring". For example if i write into my TextBox,I want the program to write a . or a / after year,month automatically (in US DateTime form after 2-2 strings,in Hungarian after 4-2 - I am from Hun). If you can only show me a form in other DateTime like the US-GB-GE or any other country,that won't be a problem at all.Hungarian DateTime would be only a formality in my program.

  2. I live in Hungary,didn't find any correct DateTime format for my Country. Format in here YYYY-MM-DD and not DD-MM-YYYY. Will it work if i simply reverse it or need to do anything else? I tried it,didn't seem to work,but maybe i did smth wrong.
    Please help!

  1. 我的问题是,我有一个文本框,我想用“自动字符串”为它写一个正确的日期时间表单。例如,如果我写入我的文本框,我希望程序编写一个 . 或 / 后年,月自动(在 2-2 个字符串之后的美国日期时间形式,在 4-2 之后的匈牙利语中 - 我来自匈奴)。如果您只能向我展示其他 DateTime 中的表格,例如 US-GB-GE 或任何其他国家/地区,那根本不是问题。匈牙利 DateTime 在我的程序中只是一种形式。

  2. 我住在匈牙利,没有为我的国家找到任何正确的 DateTime 格式。在此处格式化 YYYY-MM-DD 而不是 DD-MM-YYYY。如果我只是简单地扭转它或需要做任何其他事情,它会起作用吗?我试过了,似乎没有用,但也许我做错了。
    请帮忙!

回答by landoncz

Masked entry in a text box in WPF is not done easily. If it's a requirement that the text box have the slashes or the dashes for the date as the user enters it, I would consider using WPF Toolkit DateTime Pickeror the WPF Toolkit Masked Edit Text Box, both of which are available on Codeplex as part of the Extended WPF toolkit.

WPF 文本框中的掩码条目并不容易完成。如果要求文本框在用户输入日期时带有斜杠或破折号,我会考虑使用WPF Toolkit DateTime PickerWPF Toolkit Masked Edit Text Box,这两者都可以在 Codeplex 上作为扩展的 WPF 工具包。

If you still want to try masked text box editing on your own, here's an example I found that could be modified for a date format of your choice: WPF Masked Text Box

如果您仍然想尝试自己编辑蒙版文本框,这是我发现的一个示例,可以针对您选择的日期格式进行修改:WPF 蒙版文本框