Content sharing modality event handling

Beyond the basics topic

Learn about making your application UI responsive to the events raised by Microsoft Lync 2013 API content sharing modality in Lync 2013 conversations.

Applies to: Lync 2013 | Lync Server 2013

In this article
Content sharing modality events
Additional resources

Content sharing modality events

The sharing stage of a Lync 2013 conversation window allows conversation participants to queue and unqueue multiple types of sharing content in a logical entity that can be thought of as a content bin. Only one shareable content item can be shown on the sharing stage at a time. Any conversation presenter can be made the presenter of the active content or become a content presenter when they share content that they own.

The four events exposed by the Microsoft.Lync.Model.Conversation.Sharing.ContentSharingModality are as follows:

In addition, the ContentSharingModality raises all the events that it inherits from the base Microsoft.Lync.Model.Conversation.Modality class.

ContentAdded event

A presenter has added a new shareable content item to the content bin. The ContentSharingModality.ContentAdded event should be used to update your client UI with the title of a new content bin item. The event data state object provides a reference to the new ShareableContent object. You should register for events on the ShareableContent object when it's added to the content bin.

The following example adds the title of the new content to a list in the UI and then enables a command button.

        /// <summary>
        /// Raised when an item is added to the content bin
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _sharingModality_ContentAdded(object sender, ContentCollectionChangedEventArgs e)
        {
            AddAListItemDelegate ListAdder = new AddAListItemDelegate(AddAListItem);

            string newItem = string.Empty;
            e.Item.ActionAvailabilityChanged += _ShareableContent_ActionAvailabilityChanged;
            newItem = e.Item.Type.ToString() + "-" + e.Item.Title;

            //Invoke a delegate that updates a property on a UI control by adding the
            //title of the newly added content to a list box.
            this.Invoke(ListAdder, new object[] { Content_Listbox, newItem });

            //Invoke a delegate that enables the Share button on the UI
            this.Invoke(new EnableDisableButtonDelegate(EnableDisableButton)
                , new object[] { ContentShare_Button, true });
        }

ContentRemoved event

A presenter has removed a shareable content item from the content bin. The ContentSharingModality.ContentRemoved event is used to update your client UI to remove the title of the removed content from a content bin list and to unregister for content sharing events on the removed content.

The following example refreshes a UI list of content bin items.

        /// <summary>
        /// Raised when an item is removed from the content bin
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _sharingModality_ContentRemoved(object sender, ContentCollectionChangedEventArgs e)
        {
            //Invokes a delegate that clears and re-loads a UI list of items in the content bin.
            this.Invoke(new ClearAllListItemsDelegate(ClearAllListItems), new object[] { Content_Listbox});
            foreach (ShareableContent sc in ((ContentSharingModality)_conversation.Modalities[ModalityTypes.ContentSharing]).ContentCollection)
            {
                string newItem = sc.Type.ToString() + "-" + sc.Title;
                this.Invoke(new AddAListItemDelegate(AddAListItem), new object[] { Content_Listbox, newItem });
            }
        }

ActiveContentChanged event

A presenter has swapped one content bin sharing item for another item. The ContentSharingModality.ActiveContentChanged event tells you that a conversation participant has swapped one content bin item for a different one on the sharing stage. An application UI should show the current active content presenter and command buttons for actions that can be taken on active content. Use this event to get the new active content presenter and enable command buttons that are appropriate for the type of content that is being presented.

The following example gets the title of the newly shared content and then enables or disables the command buttons that are appropriate for the content type.

        /// <summary>
        /// Raised when one content bin item is moved off the sharing stage and is replaced by another
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _sharingModality_ActiveContentChanged(object sender, ActiveContentChangedEventArgs e)
        {
            if (e.ActiveContent != null)
            {
                _ShareableContent = e.ActiveContent;
                this.Invoke(new ChangeLabelTextDelegate(ChangeLabelText), new object[] { ActiveContent_Label, e.ActiveContent.Title });
                EnableDisableButtonDelegate ButtonDisableDelegate = new EnableDisableButtonDelegate(EnableDisableButton);
                if (e.ActiveContent.Type == ShareableContentType.PowerPoint)
                {
                    this.Invoke(ButtonDisableDelegate, new object[] { GoBack_Button, true });
                    this.Invoke(ButtonDisableDelegate, new object[] { GoForward_Button, true });
                    this.Invoke(ButtonDisableDelegate, new object[] { ClearAnnotations_Button, false });
                    Int32 hrReason;
                    if (e.ActiveContent.CanInvoke(ShareableContentAction.ClearAllAnnotations, out hrReason))
                    {
                        this.Invoke(ButtonDisableDelegate, new object[] { ClearAnnotations_Button, true });
                    }

                }
                else if (e.ActiveContent.Type == ShareableContentType.Whiteboard)
                {
                    Int32 hrReason;
                    if (e.ActiveContent.CanInvoke(ShareableContentAction.ClearAllAnnotations, out hrReason))
                    {
                        this.Invoke(ButtonDisableDelegate, new object[] { ClearAnnotations_Button, true });
                    }
                    if (e.ActiveContent.CanInvoke(ShareableContentAction.SaveAnnotation, out hrReason))
                    {
                        this.Invoke(ButtonDisableDelegate, new object[] { SaveAnnotations_Button, true });
                    }

                    this.Invoke(ButtonDisableDelegate, new object[] { GoBack_Button, false });
                    this.Invoke(ButtonDisableDelegate, new object[] { GoForward_Button, false });
                }
            }
        }

ActivePresenterChanged event

The presenter of the current active shareable content has changed or the active content has been swapped with content owned by a different presenter.

The following example updates a label in the application UI with the name of the current presenter.

        /// <summary>
        /// Raised when the active presenter in the conversation changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ContentSharing_Form_ActivePresenterChanged(object sender, ActivePresenterChangedEventArgs e)
        {
            if (e.ActivePresenter != null)
            {
                this.Invoke(
                    new ChangeLabelTextDelegate(ChangeLabelText),
                    new object[] {Presenter_Label, 
                    e.ActivePresenter.Contact.GetContactInformation(ContactInformationType.DisplayName).ToString()});
            }
        }

See also