IXRFrameworkElement::SetBinding (Compact 2013)

3/28/2014

This method binds data to a property of an IXRFrameworkElement object.


virtual HRESULT STDMETHODCALLTYPE SetBinding(
    __in const WCHAR* pTargetProperty,
    __in XRBinding* pBindingInfo
) = 0;

pTargetProperty

[in] Pointer to a string that specifies the name of the data-bound XAML for Windows Embedded property.

pBindingInfo

[in] Pointer to an XRBinding structure that specifies the data-binding information to use for the property, including the data-flow direction and a path to the custom data-source property.

Returns standard HRESULT values to indicate success or failure.

You can also bind data to an element property by using a Binding Markup Extension in XAML.

The following example code uses the SetBinding method to bind data from a TPropertyBag<Derived> object to a TextBlock. The example code works only if you already defined a custom class named StringPropertyBag that inherits from TPropertyBag<Derived>, and if you initialized the variable m_pText1 to an IXRTextBlock object in the visual tree.

Gg156069.note(en-us,WinEmbedded.80).gifImportant:
For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.
#include "XamlRuntime.h"
#include "XRPropertyBag.h"
#include "oleauto.h"

HRESULT MainPage::CreateData()
{
     HRESULT hr = S_OK;

     // Create an instance of the data source object
     XRPtr<StringPropertyBag> pObj;
     StringPropertyBag::CreateInstance(&pObj);
     pObj->InitializeProperties();

     // Set a property value in the data source object

     pObj->bstrProp1 = SysAllocString(L"New Text from Data Source");

     // Set the data source object as the data context for a TextBlock element.
     XRValue xrDataSource;
     xrDataSource.vType = VTYPE_PROPERTYBAG;
     xrDataSource.pPropertyBagVal = pObj;

     m_pText1->SetDataContext(&xrDataSource);

     // Bind data to a TextBlock element
     XRBinding pBindingInfo;
     pBindingInfo.Path = L"BinaryStringData1";
     pBindingInfo.Mode = XRBindingMode_OneWay;

     m_pText1->SetBinding(L"Text", &pBindingInfo);

     return hr; 
}

System.Windows.FrameworkElement.SetBinding

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

Show: