IXamlDirect.RemoveEventHandler(Object, XamlEventIndex, Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Removes the specified event handler from this IXamlDirect.
This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces).
public:
void RemoveEventHandler(Platform::Object ^ xamlDirectObject, XamlEventIndex eventIndex, Platform::Object ^ handler);
void RemoveEventHandler(IInspectable const& xamlDirectObject, XamlEventIndex const& eventIndex, IInspectable const& handler);
public void RemoveEventHandler(object xamlDirectObject, XamlEventIndex eventIndex, object handler);
Public Sub RemoveEventHandler (xamlDirectObject As Object, eventIndex As XamlEventIndex, handler As Object)
Parameters
- xamlDirectObject
-
Object
Platform::Object
IInspectable
A reference to the current IXamlDirect.
- 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
XamlDirect xd = XamlDirect.GetDefault();
IXamlDirect 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();
IXamlDirect^ 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
Typically, the specified handler was added by IXamlDirect.AddEventHandler(System.Object,Microsoft.UI.Xaml.Core.Direct.XamlEventIndex,System.Object,System.Boolean).
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 IXamlDirect.AddEventHandler(System.Object,Microsoft.UI.Xaml.Core.Direct.XamlEventIndex,System.Object,System.Boolean) call that originally attached the handler.