DataBinding.Expression 属性
定义
获取或设置要计算的数据绑定表达式。Gets or sets the data-binding expression to be evaluated.
public:
property System::String ^ Expression { System::String ^ get(); void set(System::String ^ value); };
public string Expression { get; set; }
member this.Expression : string with get, set
Public Property Expression As String
属性值
要计算的数据绑定表达式。The data-binding expression to be evaluated.
示例
下面的代码示例创建一个 DataBinding 对象,并将其设置为与控件的 DataBindingCollection 集合中具有 propertyName 值的参数相同的现有对象 Text 。The following code example creates a DataBinding object and sets it equal to an existing object in the control's DataBindingCollection collection that has a propertyName parameter with a value of Text. 如果集合包含一个 DataBinding 值为的对象 propertyName ,则 Text 此代码将返回对象的属性的值 Expression 。If the collection contains a DataBinding object with a propertyName value of Text, this code returns the value of the object's Expression property. 如果没有此类对象,它将返回空字符串 ( "" ) 。If there is no such object, it returns an empty string ("").
// Create a Text property with accessors that obtain
// the property value from and set the property value
// to the Text key in the DataBindingCollection class.
public string Text
{
get
{
DataBinding myBinding = DataBindings["Text"];
if (myBinding != null)
{
return myBinding.Expression;
}
return String.Empty;
}
set
{
if ((value == null) || (value.Length == 0))
{
DataBindings.Remove("Text");
}
else
{
DataBinding binding = DataBindings["Text"];
if (binding == null)
{
binding = new DataBinding("Text", typeof(string), value);
}
else
{
binding.Expression = value;
}
// Call the DataBinding constructor, then add
// the initialized DataBinding object to the
// DataBindingCollection for this custom designer.
DataBinding binding1 = (DataBinding)DataBindings.SyncRoot;
DataBindings.Add(binding);
DataBindings.Add(binding1);
}
PropertyChanged("Text");
}
}
' Create a Text property with accessors that obtain
' the property value from and set the property value
' to the Text key in the DataBindingCollection class.
Public Property [Text]() As String
Get
Dim myBinding As DataBinding = DataBindings("Text")
If Not (myBinding Is Nothing) Then
Return myBinding.Expression
End If
Return String.Empty
End Get
Set(ByVal value As String)
If value Is Nothing OrElse value.Length = 0 Then
DataBindings.Remove("Text")
Else
Dim binding As DataBinding = DataBindings("Text")
If binding Is Nothing Then
binding = New DataBinding("Text", GetType(String), value)
Else
binding.Expression = value
End If
' Call the DataBinding constructor, then add
' the initialized DataBinding object to the
' DataBindingCollection for this custom designer.
Dim binding1 As DataBinding = CType(DataBindings.SyncRoot, DataBinding)
DataBindings.Add(binding)
DataBindings.Add(binding1)
End If
PropertyChanged("Text")
End Set
End Property