[英]C# datetime binding
I have a textbox I want to bind to DateTime property to an object : 我有一个文本框,我想将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);
};
This works perfectly, when I change the textbox value, the property change. 当我更改文本框的值时,属性会发生变化,这非常完美。 Now I want the reverse (without parsing the text).
现在我要相反(不解析文本)。
I want to add a button that increment by 1 minutes myObject.DateTimeProperty. 我想添加一个按钮,使myObject.DateTimeProperty增加1分钟。 The issue is I can't do
问题是我做不到
myObject.DateTimeProperty.Minutes+=1;
nor 也不
myObject.DateTimeProperty = myObject.DateTimeProperty.AddMinutes(1);
Any ideas? 有任何想法吗?
myobjoect是否实现INotifyPropertyChanged吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.