Share via


XamlDirect.RemoveEventHandler Method

Definition

Removes the specified event handler from this IXamlDirectObject. Typically, the handler in question was added by XamlDirect.AddEventHandler.

public:
 virtual void RemoveEventHandler(IXamlDirectObject ^ xamlDirectObject, XamlEventIndex eventIndex, Platform::Object ^ handler) = RemoveEventHandler;
void RemoveEventHandler(IXamlDirectObject const& xamlDirectObject, XamlEventIndex const& eventIndex, IInspectable const& handler);
public void RemoveEventHandler(IXamlDirectObject xamlDirectObject, XamlEventIndex eventIndex, object handler);
function removeEventHandler(xamlDirectObject, eventIndex, handler)
Public Sub RemoveEventHandler (xamlDirectObject As IXamlDirectObject, eventIndex As XamlEventIndex, handler As Object)

Parameters

xamlDirectObject
IXamlDirectObject

A reference to the current IXamlDirectObject.

eventIndex
XamlEventIndex

An identifier for the event to remove the handle for specified through XamlEventIndex enum.

handler
Object

Platform::Object

IInspectable

A reference to the specified handler implementation.

Examples

The following example shows how to add/modify and remove the PointerEntered event through a specific instance of PointerEventHandler on a ToggleSwitch control from its IXamlDirectObject instance.

XamlDirect xd = XamlDirect.GetDefault();

IXamlDirectObject toggleSwitch = xd.CreateInstance(XamlTypeIndex.ToggleSwitch);

PointerEventHandler toggleSwitchPointerHandler = new PointerEventHandler((sender, args) =>
{
    if (sender is ToggleSwitch)
    {
        ((ToggleSwitch)sender).IsOn = !((ToggleSwitch)sender).IsOn;
    }
});

xd.AddEventHandler(toggleSwitch, XamlEventIndex.UIElement_PointerEntered, toggleSwitchPointerHandler);
xd.RemoveEventHandler(toggleSwitch, XamlEventIndex.UIElement_PointerEntered, toggleSwitchPointerHandler);
XamlDirect^ xd = XamlDirect::GetDefault();

IXamlDirectObject^ toggleSwitch = xd->CreateInstance(XamlTypeIndex::ToggleSwitch);

PointerEventHandler^ toggleSwitchPointerHandler = ref new PointerEventHandler([&](Platform::Object^ sender, PointerRoutedEventArgs^ args)
{
    ToggleSwitch^ ts = dynamic_cast<ToggleSwitch^>(sender);
    if (nullptr != ts)
    {
        ts->IsOn = !ts->IsOn;
    }
});

xd->AddEventHandler(toggleSwitch, XamlEventIndex::UIElement_PointerEntered, toggleSwitchPointerHandler);
xd->RemoveEventHandler(toggleSwitch, XamlEventIndex::UIElement_PointerEntered, toggleSwitchPointerHandler);

Remarks

RemoveEventHandler can only be used to remove event handlers for the events supported by the XamlEventIndex enumeration.

Calling this method has no effect if there were no handlers registered with criteria that match the input parameters for the method call.

This method ignores whether handledEventsToo parameter was true in the XamlDirect.AddEventHandler call that originally attached the handler.

Applies to

See also