...
Message Bar items are messages with a navigation tree item link an accompanying hyperlink that, when clicked, navigates the user to that a location in the WMCnavigation tree.
Adding Message Bar items
...
Items added in the manner shown above display the strLabel text as the message, followed by a link that says "Go There". If you click the link, the WMC navigates to the location specified in strDescription. You can provide customised hyperlink text by providing your own XAML content.
Flag | Description |
---|---|
NI_FLAG_MESSAGEBAR_ICONWARNING NI_FLAG_MESSAGEBAR_ICONINFO NI_FLAG_MESSAGEBAR_ICONSHIELD | The type of icon to show. Mutually exclusive. |
NI_FLAG_MESSAGEBAR_NOTIFY | Notify the item of the click. Without this flag the default behaviour is to go to a navigation location. Calls the NavItemNotify handler of the notification interface supplied in NavInsertItem |
NI_FLAG_MESSAGEBAR_USERXAML | You wish to supply the full XAML for the item. See below for details. |
...
NI_FLAG_MESSAGEBAR_NOTIFY means call NavNotifyItem, else calls NavGotoItem. If NI_FLAG_MESSAGEBAR_NOTIFY then we notify the tag, otherwise we goto the description
Custom link text
The default link text is Go There but it can be customised by providing your own XAML when inserting the element. To use custom XAML you need to set the flag NI_FLAG_MESSAGEBAR_USERXAML in the NAVSETITEM structure. strLabel then becomes the custom XAML and the Hyperlink node's Tag attribute in the XAML specifies the location to navigate to. e.g.
Code Block |
---|
void AddMessageBarItem(LPCWSTR text, LPCWSTR link) { // First get the root of the MESSAGEBAR domain NAVSETITEM messageBarRootData; memset(&messageBarRootData, 0, sizeof(NAVSETITEM)); if( !NavGetItem(_T("MESSAGEBAR"), &messageBarRootData) ) { return; // Failed to find MESSAGEBAR root } NavHandle messageBarRoot = messageBarRootData.hItem; NAVSETITEM newItem; memset(&newItem, 0, sizeof(newItem)); newItem.flags = NI_FLAG_MESSAGEBAR_USERXAML; newItem.EventMask = NI_EVENT_MOUSE_LCLICK; std::wstring strLabel; FormatString(strLabel, L"<Image Source='2400'/><TextBlock Padding='3, 0, 20, 0' VerticalAlignment='Center'>This is the message: <Hyperlink Tag='MESSAGEBAR\\MyComponent'>%s</Hyperlink></TextBlock>", CResString(IDS_LABEL_THEREISANOTIFICATION).GetBuffer(0), CResString(IDS_LABEL_GOTONOTIFICATIONS).GetBuffer(0)); ItemNew.strLabel = strLabel.c_str(); ItemNew.strDescription = _T("{Notifications}"); // where to go to ItemNew.lParam = (LPARAM)this; ItemNew.pInterface = &gTaskInterface; NavInsertItem(hMessageBar, _T("NotificationWarning"), &ItemNew); hWarning = ItemNew.hItem; } |