The sample code is as follows:
// Create the source string
String s = "Hello ";
// Create the binding description
Binding B = new Binding ("");
B. Mode = BindingMode. OneTime;
B. Source = s;
// Attach the binding to the target
MyText. SetBinding (TextBlock. TextProperty, B );
Example 2:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Net;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. Documents;
Using System. Windows. Input;
Using System. Windows. Media;
Using System. Windows. Media. Animation;
Using System. Windows. Shapes;
Using System. Xml. Linq;
Namespace TextBoxDemo
{
Public partial class MainPage: UserControl
{
Public MainPage ()
{
InitializeComponent ();
}
String valueToSearch; // input query Conditions
Private void btnSearch_Click (object sender, RoutedEventArgs e)
{
If (string.IsNullOrEmpty(this.txt NameSearch. Text. Trim ()))
{
MessageBox. Show ("Enter the query condition! ");
Return;
}
Else {
ValueToSearch = txtNameSearch. Text. Trim ();
WebClient client = new WebClient ();
Client. DownloadStringCompleted + = new DownloadStringCompletedEventHandler (client_DownloadStringCompleted );
Client. DownloadStringAsync (new Uri ("../XML/Employees. xml", UriKind. Relative ));
}
}
Private void client_DownloadStringCompleted (object sender, DownloadStringCompletedEventArgs e ){
XDocument document = XDocument. Parse (e. Result );
XElement el = XElement. Load (document. CreateReader ());
Var items = (
From item in el. Elements ("employess"). Elements ("item ")
Where item. Element ("name"). Value. StartsWith (valueToSearch)
Select new Employee
{
EName = (string) item. Element ("name ")),
ESex = (string) item. Element ("gender ")}
). Take (1 );
If (items. Count () = 0)
{
MessageBox. Show ("Sorry, it cannot be found! ");
SPContent. DataContext = null;
}
Else {
Employee p = items. ElementAt <Employee> (0 );
System. Windows. Data. Binding binding = new System. Windows. Data. Binding ("");
Binding. Mode = System. Windows. Data. BindingMode. OneWay;
Binding. Source = p. EName;
TxtName. SetBinding (TextBox. TextProperty, binding );
}
}
}
Class Employee {
Public string EName {get; set ;}
Public string ESex {get; set ;}
}
}