One way and two way binding : Binding « Windows Presentation Foundation « VB.Net Tutorial






<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:WpfApplication1.CustomElementBinding" 
        Title="Custom Element Binding Demo">
    <StackPanel>
    <ScrollBar Name="scroll"
               Orientation="Horizontal"
               Margin="24" 
               Maximum="100"
               LargeChange="10"
               SmallChange="1" 
               Value="{Binding ElementName=simple, Path=Number,Mode=TwoWay}" />
    <src:SimpleElement Number="{Binding ElementName=scroll,Path=Value,Mode=OneWay}"/>
    </StackPanel>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Globalization
Imports System.Windows
Imports System.Windows.Media

Namespace WpfApplication1.CustomElementBinding
  Class SimpleElement
    Inherits FrameworkElement
    Public Shared NumberProperty As DependencyProperty
    Shared Sub New()
      NumberProperty = DependencyProperty.Register("Number", GetType(Double), GetType(SimpleElement), New FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender))
    End Sub
    Public Property Number() As Double
      Get
        Return CDbl(GetValue(NumberProperty))
      End Get
      Set
        SetValue(NumberProperty, value)
      End Set
    End Property
    Protected Overrides Function MeasureOverride(sizeAvailable As Size) As Size
      Return New Size(200, 250)
    End Function
    Protected Overrides Sub OnRender(dc As DrawingContext)
      dc.DrawText(New FormattedText(Number.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, New Typeface("Times New Roman"), 12, SystemColors.WindowTextBrush), New Point(0, 0))
    End Sub
  End Class
End Namespace
WPF One Way And Two Way Binding








16.95.Binding
16.95.1.Bind to a Property of a UI ElementBind to a Property of a UI Element
16.95.2.Bind a Property of an Element to ItselfBind a Property of an Element to Itself
16.95.3.Specify a Default Value for a BindingSpecify a Default Value for a Binding
16.95.4.Create a Two-Way BindingCreate a Two-Way Binding
16.95.5.Debug Bindings Using Attached PropertiesDebug Bindings Using Attached Properties
16.95.6.String Array ResourceString Array Resource
16.95.7.Bind animate target value to Canvas(Window) widthBind animate target value to Canvas(Window) width
16.95.8.Display Current Date and Time: binding the DateTime.Now to LabelDisplay Current Date and Time: binding the DateTime.Now to Label
16.95.9.One way and two way bindingOne way and two way binding
16.95.10.Custom Element Binding WindowCustom Element Binding Window
16.95.11.Get XmlElement from Bounded viewGet XmlElement from Bounded view
16.95.12.Customize UpdateSourceExceptionFilterCustomize UpdateSourceExceptionFilter
16.95.13.Assign your own class to DataContent and bind to TextBoxAssign your own class to DataContent and bind to TextBox
16.95.14.Async bindingAsync binding
16.95.15.Null property bindingNull property binding
16.95.16.Binding Property with ExceptionBinding Property with Exception
16.95.17.Hierarchical Binding for three level nested objectsHierarchical Binding for three level nested objects
16.95.18.BindingOperations.GetBindingExpressionBindingOperations.GetBindingExpression
16.95.19.Bind to enum typesBind to enum types
16.95.20.Bind to a MethodBind to a Method
16.95.21.Manual Update TargetManual Update Target
16.95.22.Bind to the Values of an EnumerationBind to the Values of an Enumeration
16.95.23.Master Detail BindingMaster Detail Binding
16.95.24.Data binding using collections composed of mixed types of data.Data binding using collections composed of mixed types of data.
16.95.25.Binding Environment InfoBinding Environment Info
16.95.26.Bind to an ADO.NETDataSetBind to an ADO.NETDataSet
16.95.27.Text Data BindingText Data Binding
16.95.28.Bind to an Existing Object InstanceBind to an Existing Object Instance
16.95.29.Digital ClockDigital Clock
16.95.30.Use Data Triggers to Change the Appearance of Bound DataUse Data Triggers to Change the Appearance of Bound Data