Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3930794
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:17:27+00:00 2026-05-19T23:17:27+00:00

Can someone please point me to a working example of how I’m supposed to

  • 0

Can someone please point me to a working example of how I’m supposed to do data binding in Silverlight for Windows Embedded (SWE). I have seen a showcase of it, so it appears to be possible. And I’ve read here that I need to implement IXRPropertyBag to make it work, but have yet to find (working) instructions on how to do it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:17:27+00:00Added an answer on May 19, 2026 at 11:17 pm

    I managed to get data binding working between the IsChecked property of two ToggleButton elements, based on the insanely bad example found in the help files that came with the WCE7 CTP. I would have expected to set the data context and data bindings in XAML, but the documentation told me to code it.

    First you have to create a class that implements IXRPropertyBag. Then you have to set the data context and data binding to an instance of this property bag from code.

    I’m sorry for the lack of a naming convention in the code, but it is still far better than the example that was provided by Microsoft. It is also not as generic as it could be, but I’ll leave that refactoring up to you.

    MyPropertyBag.h:

    #pragma once
    #include "windows.h"
    #include "XamlRuntime.h"
    #include "XRCustomEvent.h"
    #include "XRPtr.h"
    
    class __declspec(uuid("3C6FFC6F-17A8-4976-B034-B4FE3BFF530A"))
    MyPropertyBag : public IXRPropertyBag
    {
    private:
        LONG m_cRef;
        IXRCustomEvent<XRPropertyChangedCustomEventArgs, IXRPropertyBag> *pRadioEvent;
        XRThreeState RadioState;
    
    public:
        MyPropertyBag(void);
    
        HRESULT STDMETHODCALLTYPE GetValue(__in const WCHAR* pstrPropertyName, __out XRValue *pValue);
        HRESULT STDMETHODCALLTYPE SetValue(__in const WCHAR* pstrPropertyName, __in XRValue *pValue);
        HRESULT STDMETHODCALLTYPE GetPropertyChangedEvent(__out IXRCustomEvent<XRPropertyChangedCustomEventArgs, IXRPropertyBag>** ppEvent);
    
        HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID * ppvObj);
        ULONG STDMETHODCALLTYPE AddRef();
        ULONG STDMETHODCALLTYPE Release();
    };
    

    MyPropertyBag.cpp:

    #include "StdAfx.h"
    #include "MyPropertyBag.h"
    
    extern "C" const GUID __declspec(selectany) IID_MyPropertyBag = __uuidof(IXRPropertyBag);
    
    MyPropertyBag::MyPropertyBag(void)
    {
        RadioState = XRThreeState_Unchecked;
        pRadioEvent = CreateCustomEvent<XRPropertyChangedCustomEventArgs, IXRPropertyBag>();
    }
    
    // IXRPropertyBag implementation:
    
    HRESULT MyPropertyBag::GetValue(__in const WCHAR* pstrPropertyName, __out XRValue *pValue)
    {
        HRESULT hr = E_FAIL;
        if (0 == wcscmp(pstrPropertyName, L"RadioState"))
        {
            pValue->vType = VTYPE_INT;
            pValue->IntVal = (int)RadioState;
            hr = S_OK;
        }
    
        return hr;
    }
    
    HRESULT MyPropertyBag::SetValue(__in const WCHAR* pstrPropertyName, __in XRValue *pValue)
    {
        HRESULT hr = E_FAIL;
    
        if (0 == wcscmp(pstrPropertyName, L"RadioState"))
        {
            RadioState = (XRThreeState)pValue->IntVal;
            XRPropertyChangedCustomEventArgs eventArgs;
            eventArgs.PropertyName = pstrPropertyName;
            pRadioEvent->Raise(this, &eventArgs);
            hr = S_OK;
        }
    
        return hr;
    }
    
    HRESULT MyPropertyBag::GetPropertyChangedEvent(IXRCustomEvent<XRPropertyChangedCustomEventArgs, IXRPropertyBag>** ppEvent)
    {
        *ppEvent = pRadioEvent;
        return S_OK;
    }
    // end of IXRPropertyBag implementation.
    
    // IUnknown implementation:
    
    HRESULT MyPropertyBag::QueryInterface(REFIID riid, LPVOID * ppvObj)
    {
        if (!ppvObj)
            return E_INVALIDARG;
    
        *ppvObj = NULL;
        if (riid == IID_IUnknown || riid == IID_MyPropertyBag)
        {
            *ppvObj = (LPVOID)this;
            AddRef();
            return NOERROR;
        }
    
        return E_NOINTERFACE;
    }
    
    ULONG MyPropertyBag::AddRef()
    {
        InterlockedIncrement(&m_cRef);
        return m_cRef;
    }
    
    ULONG MyPropertyBag::Release()
    {
        ULONG ulRefCount = InterlockedDecrement(&m_cRef);
        if (0 == m_cRef)
        {
            delete this;
        }
        return ulRefCount;
    }
    // end of IUnknown implementation.
    

    Create the shared property bag and call BindDataToControl for both toggle buttons before calling StartDialog on the visual host:

    // Data bindings
    XRPtr<MyPropertyBag> viewModel(new MyPropertyBag());
    BindDataToControl(pTb1, viewModel);
    BindDataToControl(pTb2, viewModel);
    
    // save the exit code for WinMain
    hr = m_pVisualHost->StartDialog(&uiExitCode);
    SetWinMainResultCode(uiExitCode);  
    

    This is what BindDataToControl would look like, to set the DataContext and the binding:

    inline void App::BindDataToControl(IXRFrameworkElement* pElement, IXRPropertyBag* pPropertyBag)
    {
        // Set the binding value and source property
        XRBinding binding;
        binding.Mode = XRBindingMode_TwoWay;
        binding.Path = L"RadioState";
        pElement->SetBinding(L"IsChecked", &binding); 
    
        // Convert the data source object to an XRValue
        XRValue dataContext;
        dataContext.vType = VTYPE_PROPERTYBAG;
        dataContext.pPropertyBagVal = pPropertyBag;
    
        // Set the data source object as the data context for the option button
        pElement->SetDataContext(&dataContext);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please provide an example of how to store, and read xml data
Can someone please point me out a hash function (preferably an implementation) which would
Can someone please point me to instructions for installing the latest Indy10 in Delphi
it's assembler right? can someone please point out the progression that we've had in
Could someone please point out a site where I can find an algorithm to
Can someone please correct me, I've found this example online and bunch of others
Can you someone please point in me in a direction, sample code or an
Can some one point me to a working example of xsl transformation using the
I am working with Nop Commerce and wondering if someone can please help me
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.