IXRListBoxItem (Windows Embedded CE 6.0)
1/6/2010
This class represents a selectable item in a list box.
Syntax
class IXRListBoxItem : public IXRContentControl
Methods
Method | Description |
---|---|
Retrieves a value that indicates whether this list-box item is selected. |
|
Sets a value that indicates whether this list-box item is selected. |
Remarks
An IXRListBox object contains a collection of IXRListBoxItem objects. This collection is stored in an IXRItemCollection object, which can be retrieved by calling IXRItemsControl::GetItems. To add IXRListBoxItem items to the retrieved IXRItemCollection object, you can use its inherited methods IXRCollection<In_T, Out_T>::Add or IXRCollection<In_T, Out_T>::Insert.
IXRListBoxItem inherits from IXRContentControl. You can retrieve the content of this list-box item by calling IXRContentControl::GetContent, and you can set the content of this list-box item by calling IXRContentControl::SetContent.
To enable each list-box item to respond to user interaction, you can add event handlers to its events, such as MouseEnter or MouseLeftButtonDown, by calling the inherited methods IXRUIElement::AddMouseEnterEventHandler or IXRUIElement::AddMouseLeftButtonDownEventHandler. To create a visual behavior for each list-box item when the list box is loaded, you can start a storyboard animation in an event handler, and then add its delegate to a list-box item by calling IXRFrameworkElement::AddLoadedEventHandler. For more information about event handlers, see Handle Events in Silverlight for Windows Embedded.
Example
The following code example creates an IXRListBoxItem object that has an image Brush as its background. It also attaches delegates to the item which represent event handlers that are already implemented in a custom object MyListBoxEventHandlers. The event handlers enable the object to respond to events, such as when the user presses the left mouse button while it is resting over the list-box item.
Note
To make the following code example easier to read, security checking and error handling are not included. This code sample should not be used in a release configuration unless it has been modified to include them.
#include "stdafx.h"
#include "XamlRuntime.h"
#include "XRDelegate.h"
void CreateListBoxItem(IXRApplication* pApplication, IXRListBox* pListBox, MyListBoxEventHandlers* pObject)
{
// Initialize variables
IXRListBoxItem* pLocationBasedItem;
IXRImageBrush* pImageBrush;
IXRBitmapImage* pDinerBitmap;
float itemHeight = 50;
float itemWidth = 100;
XRValue* itemValue;
itemValue.vType = VTYPE_STRING;
itemValue.pstringVal = "Ninth Avenue Diner";
// Create new XR objects
pApplication->CreateObject(IID_IXRListBoxItem, &pLocationBasedItem);
pApplication->CreateObject(IID_IXRImageBrush, &pImageBrush);
pApplication->CreateObject(IID_IXRBitmapImage, &pDinerBitmap);
// Set values for the image Brush to paint the list-box item
pDinerBitmap->SetUriSource(L"Assets/ninthAve.png");
pImageBrush->SetImageSource(&pDinerBitmap);
// Set values for the list-box item
pLocationBasedItem->AddMouseDownEventHandler(CreateDelegate(&pObject, &MyListBoxEventHandlers::OnMouseDown));
pLocationBasedItem->AddMouseEnterEventHandler(CreateDelegate(&pObject, &MyListBoxEventHandlers::OnMouseEnter));
pLocationBasedItem->AddMouseLeaveEventHandler(CreateDelegate(&pObject, &MyListBoxEventHandlers::OnMouseLeave));
pLocationBasedItem->AddOnLoadedEventHandler(CreateDelegate(&pObject, &MyListBoxEventHandlers::OnLoaded));
pLocationBasedItem->SetHeight(itemHeight);
pLocationBasedItem->SetWidth(itemWidth);
pLocationBasedItem->SetContent(&itemValue);
pLocationBasedItem->SetBackground(&pImageBrush);
// Add the new list-box item to the item collection
IXRItemCollection* pItemCollection;
UINT index = 0;
pListBox->GetItems(&pItemCollection);
pItemCollection->Insert(index, &pLocationBasedItem);
}
This code example assumes that you have already created an IXRApplication instance, generated a visual tree, and that an IXRListBox object already exists to add this list-box item to. It also assumes that you have implemented event-handling code for the list-box event handlers in a custom object named MyListBoxEventHandlers. For more information about the classes used in this code example, see IXRListBox, IXRItemCollection, IXRImageBrush, and IXRBitmapImage.
Inheritance Hierarchy
IXRListBoxItem
.NET Framework Equivalent
System.Windows.Controls.ListBoxItem
Requirements
Header | XamlRuntime.h |
sysgen | SYSGEN_XAML_RUNTIME |
Windows Embedded CE | Windows Embedded CE 6.0 R3 |