{"record":{"id":"befa020f0525577e","repo":"dotnet/wpf","slug":"microsoft-windows-controls-sr-uia-operationcannotbeperformed-befa02","errorCode":null,"errorMessage":"Microsoft.Windows.Controls.SR.UIA_OperationCannotBePerformed","messagePattern":"Microsoft\\.Windows\\.Controls\\.SR\\.UIA_OperationCannotBePerformed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonSplitButtonAutomationPeer.cs","lineNumber":74,"sourceCode":"                // When IsCheckable is false, InvokePattern should be used\n                return this;\n            }\n\n            return base.GetPattern(patternInterface);\n        }\n\n        #endregion\n\n        #region IToggleProvider Members\n\n        void IToggleProvider.Toggle()\n        {\n            if (!IsEnabled())\n                throw new ElementNotEnabledException();\n\n            if (!OwningSplitButton.IsCheckable)\n            {\n                throw new InvalidOperationException(Microsoft.Windows.Controls.SR.UIA_OperationCannotBePerformed);\n            }\n\n            if (OwningSplitButton.HeaderButton != null)\n            {\n                ToggleButtonAutomationPeer headerButtonAutomationPeer = CreatePeerForElement(OwningSplitButton.HeaderButton) as ToggleButtonAutomationPeer;\n                if (headerButtonAutomationPeer != null)\n                {\n                    ((IToggleProvider)headerButtonAutomationPeer).Toggle();\n                }\n            }\n        }\n\n        ToggleState IToggleProvider.ToggleState\n        {\n            get\n            {\n                return OwningSplitButton.IsChecked ? ToggleState.On : ToggleState.Off;\n            }","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Automation/Peers/RibbonSplitButtonAutomationPeer.cs#L56-L92","documentation":"RibbonSplitButtonAutomationPeer.Toggle() implements IToggleProvider, but toggling is only valid when the RibbonSplitButton's IsCheckable property is true (the button behaves like a checkable toggle). For non-checkable split buttons, Toggle() throws InvalidOperationException (SR.UIA_OperationCannotBePerformed) because TogglePattern is not applicable. Note it first throws ElementNotEnabledException if the control is disabled.","triggerScenarios":"Calling Toggle() on a RibbonSplitButton whose IsCheckable is false; UIA clients that iterate all patterns and call Toggle regardless of IsCheckable.","commonSituations":"UIA test scripts toggling split buttons; misconfigured RibbonSplitButton in XAML missing IsCheckable=\"True\" when the app intends checkbox-like behavior.","solutions":["Set IsCheckable=\"True\" on the RibbonSplitButton if toggle semantics are desired","For non-checkable split buttons, use Invoke() (or invoke the header button) instead of Toggle()","Check OwningSplitButton.IsCheckable before calling Toggle() in automation code","Catch InvalidOperationException and fall back to Invoke for non-checkable buttons"],"exampleFix":"// before\n((TogglePattern)splitButtonPeer.GetPattern(TogglePattern.Pattern)).Toggle();\n// after\nif (splitButton.IsCheckable)\n    ((TogglePattern)splitButtonPeer.GetPattern(TogglePattern.Pattern)).Toggle();\nelse\n    ((InvokePattern)splitButtonPeer.GetPattern(InvokePattern.Pattern)).Invoke();","handlingStrategy":"validation","validationCode":"bool canToggle = splitButton.IsCheckable && splitButton.IsEnabled;\nif (!canToggle) { /* use Invoke or skip */ }","typeGuard":"bool IsToggleable(RibbonSplitButton b) => b.IsCheckable;\n","tryCatchPattern":"try { togglePattern.Toggle(); }\ncatch (InvalidOperationException) { /* not checkable: use Invoke instead */ invokePattern?.Invoke(); }","preventionTips":["Set IsCheckable=\"True\" in XAML when toggle behavior is intended","Choose TogglePattern vs InvokePattern based on IsCheckable","Check IsEnabled() first to distinguish ElementNotEnabledException","Avoid calling every pattern an element exposes in test harnesses"],"tags":["uia","wpf","ribbon","togglepattern","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}