繁体   English   中英

C#日期时间绑定

[英]C# datetime binding

我有一个文本框,我想将DateTime属性绑定到一个对象:

myTextBox.DataBindings.Add("Text",myObject,"DateTimeProperty")
myTextBox.DataBindings["Text"].FormatString = "HH:mm";
myTextBox.DataBindings["Text"].FormattingEnabled = true;
myTextBox.DataBindings["Text"].BindingComplete +=
            delegate(object sender, BindingCompleteEventArgs e)
            {
                if (e.Exception is FormatException)
                    MessageBox.Show("Wrong formating, should be :" +myTextBox.DataBindings["Text"].FormatString);
            };

当我更改文本框的值时,属性会发生变化,这非常完美。 现在我要相反(不解析文本)。

我想添加一个按钮,使myObject.DateTimeProperty增加1分钟。 问题是我做不到

 myObject.DateTimeProperty.Minutes+=1;

也不

 myObject.DateTimeProperty = myObject.DateTimeProperty.AddMinutes(1);

有任何想法吗?

myobjoect是否实现INotifyPropertyChanged吗?

暂无
暂无

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

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