开发者

Creating a control bound to a variable

开发者 https://www.devze.com 2023-02-14 09:19 出处:网络
Is it possible to create a textbox开发者_如何学C or other control that is bound to a variable or property?

Is it possible to create a textbox开发者_如何学C or other control that is bound to a variable or property? I want to have a control that will show the current value of a control and update the variable with a new value if the control changes.

Is there some control I could download that already has this?


Would DataBindings be what your looking for? Binds a control to a property :

myTextbox.databindings.add("text", classWithProperty, "propertyName")

That's how I did it in VB.NET, but i'm a bit rusty.

EDIT:

I believe you need to implement iNotifyPropertyChanged for the values to update:

Public Class YourClassWithProperty
Implements INotifyPropertyChanged

Then make a function :

Public Sub OnPropertyChanged(ByVal name As String)
    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub

After, call the function in your property's "set" area :

Example :

Public Property Name() As String
    Get
        Return personName
    End Get
    Set(ByVal value As String)
        personName = value

        OnPropertyChanged("Name")
    End Set
End Property

Examples taken from msdn : http://msdn.microsoft.com/en-us/library/ms743695.aspx


Create a simple Textbox, add a event for example ´onLostFocus´ and update your variable there.

0

精彩评论

暂无评论...
验证码 换一张
取 消