Skip to content

Latest commit

 

History

History
75 lines (53 loc) · 3.34 KB

xamldirect_removeeventhandler_2027037099.md

File metadata and controls

75 lines (53 loc) · 3.34 KB
-api-id -api-type ms.custom
M:Windows.UI.Xaml.Core.Direct.XamlDirect.RemoveEventHandler(Windows.UI.Xaml.Core.Direct.IXamlDirectObject,Windows.UI.Xaml.Core.Direct.XamlEventIndex,System.Object)
winrt method
RS5

Windows.UI.Xaml.Core.Direct.XamlDirect.RemoveEventHandler

-description

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

-parameters

-param xamlDirectObject

A reference to the current IXamlDirectObject.

-param eventIndex

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

-param handler

A reference to the specified handler implementation.

-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.

-see-also

XamlDirect.AddEventHandler, XamlDirect.AddEventHandler, UIElement.AddHandler, UIElement.RemoveHandler

-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);