XamlDirect.RemoveEventHandler(IXamlDirectObject, XamlEventIndex, Object) XamlDirect.RemoveEventHandler(IXamlDirectObject, XamlEventIndex, Object) XamlDirect.RemoveEventHandler(IXamlDirectObject, XamlEventIndex, Object) XamlDirect.RemoveEventHandler(IXamlDirectObject, XamlEventIndex, Object) Method

Definition

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

public : void RemoveEventHandler(IXamlDirectObject xamlDirectObject, XamlEventIndex eventIndex, Platform::Object handler)
void RemoveEventHandler(IXamlDirectObject xamlDirectObject, XamlEventIndex eventIndex, winrt::Windows::Foundation::IInspectable handler) const;
public void RemoveEventHandler(IXamlDirectObject xamlDirectObject, XamlEventIndex eventIndex, Object handler)
Public Sub RemoveEventHandler(xamlDirectObject As IXamlDirectObject, eventIndex As XamlEventIndex, handler As Object)

Parameters

xamlDirectObject
IXamlDirectObject IXamlDirectObject

A reference to the current IXamlDirectObject.

eventIndex
XamlEventIndex XamlEventIndex

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

handler
Object Object

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.