One of the data bindings in Windows Phone 8.1

Source: Internet
Author: User
Tags blank page

Data binding, as the name implies, two essentials: first, data, but binding

But again, who binds the data to whose attributes, this sentence dear the four key pairs of data bindings: Binding target object, target genus

binding source, and the value to bind in the binding source.


According to the binding object and the binding source to divide, in fact there are two kinds:

UI control as a binding object, UI control as a binding source (data source)

The UI control acts as a binding object, and the custom data object is defined as the binding source (data source,. cs)

Whether the former or the latter, the only use of the binding of the artifact to set. The ElementName attribute and the Path property of the binding are used primarily

Two properties. The ElementName property is assigned the value of the name of the data source control, and the Path property assigns a value to a property of the data source control, which

Sex is a reflection of a data change in a data source control.

This method is more flexible, there are a variety of situations and manifestations, as follows (only the path is written, does not mean that there is no elementname, for UI to UI is

ElementName, there is no elementname for custom data sources to the UI):

(1) Binding Path=propertyname

As a UI binding ui:binding Elementname=grid,path=width

Binding as a custom data source: Binding Path = PropertyName

(2) Binding Path = Screen.height, can be seen as a binding source is a computer object, screen is a computer property, and

Height is also a property of screen, so you can see the properties of the properties that are bound to the data source

(3) Binding Path = (grid.column)

(4) Binding Path = screen[1]

(5) Binding Path = screen.screeninfo[productor,date]

(6) Binding Path = "[(Sys:int32) 3, (Sys:int32)]", SYS represents the System namespace

(7) Binding Path =/, if the source is a collection view, the current item is established

(8) Binding Path =/screen/publisher

(9) binding Path =. Equivalent binding

Furthermore, there are three binding modes of binding: Onetime,oneway,twoway

OneTime: Represents a binding, that is, first bound once, and then regardless of whether the data source changes are not updated to the binding target. This means that only the data is displayed and

A static data binding that does not update the data.

OneWay: Default binding mode. Represents a one-way binding, that is, when the binding source data changes, changes are updated to the binding target, which is suitable for displaying the variable

The data.

TwoWay: Represents two-way binding, that is, when data on the binding source data and binding targets changes, it affects and reflects each other. This practice will wear out

Additional performance is not required to be used best not to use.


In fact, for a UI control as a binding object, the UI control as a binding source (data source) is nothing more than using the binding setting above, the focus is

In a UI control as a binding object, a custom data object is defined in this case as a binding source (data source,. cs), because this relative use is more

More free and flexible and closer to business and logic needs.


Typically, the DataContext property is used to bind to the source object, and the DataContext property represents the data context for the UI element of the Windows Phone, which can be

Provides data to UI elements. If you set its Datcontext property to the source object at the top-most page, the entire page can use that number

data provided by the source. The sample code is as follows:

XAML Code:

<page    x:class= "App1.databinddemo1"    xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation "    xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "    xmlns:local=" Using:app1 "    xmlns:d="/http/ schemas.microsoft.com/expression/blend/2008 "    xmlns:mc=" http://schemas.openxmlformats.org/ markup-compatibility/2006 "    mc:ignorable=" D "    background=" {ThemeResource Applicationpagebackgroundthemebrush} ">    <Grid>        <textblock horizontalalignment=" Center "text=" {Binding Test} "fontsize="/>    </Grid></Page>

. CS Code:

Using system;using system.collections.generic;using system.io;using system.linq;using System.runtime.interopservices.windowsruntime;using windows.foundation;using Windows.Foundation.Collections; Using windows.ui.xaml;using windows.ui.xaml.controls;using windows.ui.xaml.controls.primitives;using windows.ui.xaml.data;using windows.ui.xaml.input;using windows.ui.xaml.media;using Windows.UI.Xaml.Navigation;//" Blank page "Item template in http://go.microsoft.com/fwlink/?    linkid=390556 on the namespace app1{////<summary>//////for self or to navigate to a blank page inside the Frame.            </summary> public sealed partial class Databinddemo1:page {public class TestData {        public string test {get; set;} } TestData TestData = new TestData () {test= "This is bound data!        " }; Public DataBindDemo1 () {this.            InitializeComponent (); This.        DataContext = TestData;        }///<summary>///This page will be called when it is displayed in Frame. </summary>//<param name= "E" > Describes how to access event data for this page. This parameter is typically used for configuration pages. </param> protected override void Onnavigatedto (NavigationEventArgs e) {}}}


One of the data bindings in Windows Phone 8.1

Related Article

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.