Silverlight tips-FrameworkElement. SetBinding Method

Source: Internet
Author: User

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 ;}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.