程序主要是要设置各种不同类型的参数。
public abstract class ParamBase : INotifyPropertyChanged
{
public bool ThrowOnInvalidPropertyName { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String propertyName)
{
this.VerifyPropertyName(propertyName);
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
定义一个参数泛型类,包含值和单位:public class ParamT<ValueType, UnitType> : ParamBase
{
public ParamT(ValueType valueType,UnitType unitType)
{
this._value = valueType;
this._unit = unitType;
} private ValueType _value;
private UnitType _unit; public ValueType Value
{
get { return this._value; }
set
{
this._value = value;
base.NotifyPropertyChanged("Value");
}
} public UnitType Unit
{
get { return this._unit; }
set
{
this._unit = value;
base.NotifyPropertyChanged("Unit");
}
}
}
定制参数设置的View,名为EditParam:
一个UserControl,里面有TextBlock显示参数名,TextBox设置参数,TextBlock显示单位名,一个定制按钮,弹出list,选择单位。参数是进行分类了的,比如主分类一
class SortA:ParamBase
{
//里面有若干参数,
public ParamT<float, UnitTime> StartTime
{
get { return _startTime; }
set
{
if (_startTime== value)
return;
_startTime= value;
base.NotifyPropertyChanged("StartTime");
}
}
}
====
EditParam的TextBox的Text属性直接binding到SortA.StartTime.Value属性,
在这种情况下,我如何做数据校验?
public abstract class ParamBase : INotifyPropertyChanged
{
public bool ThrowOnInvalidPropertyName { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String propertyName)
{
this.VerifyPropertyName(propertyName);
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
定义一个参数泛型类,包含值和单位:public class ParamT<ValueType, UnitType> : ParamBase
{
public ParamT(ValueType valueType,UnitType unitType)
{
this._value = valueType;
this._unit = unitType;
} private ValueType _value;
private UnitType _unit; public ValueType Value
{
get { return this._value; }
set
{
this._value = value;
base.NotifyPropertyChanged("Value");
}
} public UnitType Unit
{
get { return this._unit; }
set
{
this._unit = value;
base.NotifyPropertyChanged("Unit");
}
}
}
定制参数设置的View,名为EditParam:
一个UserControl,里面有TextBlock显示参数名,TextBox设置参数,TextBlock显示单位名,一个定制按钮,弹出list,选择单位。参数是进行分类了的,比如主分类一
class SortA:ParamBase
{
//里面有若干参数,
public ParamT<float, UnitTime> StartTime
{
get { return _startTime; }
set
{
if (_startTime== value)
return;
_startTime= value;
base.NotifyPropertyChanged("StartTime");
}
}
}
====
EditParam的TextBox的Text属性直接binding到SortA.StartTime.Value属性,
在这种情况下,我如何做数据校验?
解决方案 »
- 锻炼下,看谁能弄出来,C#编程技巧!
- tcp/udp打洞的服务端位置
- WinForm中DataTable导出为Excel后,如何获取Excel文件地址?
- 为什么总是说“无法将类型"string"转换为"char"”?
- sql server2000的奇怪现象
- 简单正则表达式
- 请教把Windows窗体的数据赋值给一个强类型数据集,调试显示“在位置 0 处没有任何行”是什么原因呀?
- 请问关于bitmap释放问题
- 痛苦得不想活,程序在运行时象死了一样
- 如何在注册表中正确注册Crystal Reports for Visual Studio.NET?????
- C#调用matlab计算方程问题
- 关于C#做游戏的一个效率问题
如:范围是1000-3000,
那么你输入1就自动变成1000了,如果输入1200就选中第二个0输入2,要不就大于3000了变成3000了!或者也可以再LostFocus事件中做。