{"record":{"id":"f867b1a94e60e5d6","repo":"dotnet/wpf","slug":"sr-bitmapcachebrush-opacitychanged","errorCode":null,"errorMessage":"SR.BitmapCacheBrush_OpacityChanged","messagePattern":"SR\\.BitmapCacheBrush_OpacityChanged","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs","lineNumber":353,"sourceCode":"                _reentrancyFlag = true;\n                return true;\n            }\n        }\n\n        /// <summary>\n        /// Exits the BitmapCacheBrush. For more details see Enter method.\n        /// </summary>\n        internal void Exit()\n        {\n            Debug.Assert(_reentrancyFlag); // Exit must be matched with Enter. See Enter comments.\n            _reentrancyFlag = false;\n        }       \n\n        private static object CoerceOpacity(DependencyObject d, object value)\n        {\n            if ((double)value != (double)OpacityProperty.GetDefaultValue(typeof(BitmapCacheBrush)))\n            {\n                throw new InvalidOperationException(SR.BitmapCacheBrush_OpacityChanged);\n            }\n            return 1.0;\n        }\n\n        private static object CoerceTransform(DependencyObject d, object value)\n        {\n            if ((Transform)value != (Transform)TransformProperty.GetDefaultValue(typeof(BitmapCacheBrush)))\n            {\n                throw new InvalidOperationException(SR.BitmapCacheBrush_TransformChanged);\n            }\n            return null;\n        }\n\n        private static object CoerceRelativeTransform(DependencyObject d, object value)\n        {\n            if ((Transform)value != (Transform)RelativeTransformProperty.GetDefaultValue(typeof(BitmapCacheBrush)))\n            {\n                throw new InvalidOperationException(SR.BitmapCacheBrush_RelativeTransformChanged);","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs#L335-L371","documentation":"BitmapCacheBrush deliberately does not support a non-default Opacity; the CoerceOpacity coercion callback throws whenever Opacity is set to anything other than the default (1.0). The brush's opacity must be controlled through the cached content or the Target brush instead.","triggerScenarios":"Setting BitmapCacheBrush.Opacity to any value other than 1.0 (the default), in code (brush.Opacity = 0.5), XAML (<BitmapCacheBrush Opacity=\"0.5\"/>), or via animation/binding targeting Opacity.","commonSituations":"Developers assuming Brush.Opacity works uniformly across brush types and applying opacity to BitmapCacheBrush copied from another brush's usage.","solutions":["Do not set Opacity on BitmapCacheBrush; leave it at the default 1.0","Apply the desired opacity to the Target brush or to the element rendering the brush (UIElement.Opacity)","If opacity effects are needed, wrap the cached content with an element/brush that supports opacity"],"exampleFix":"// before\nvar brush = new BitmapCacheBrush { Target = visual, Opacity = 0.5 };\n// after\nvar brush = new BitmapCacheBrush { Target = visual };\nelement.Opacity = 0.5; // or set opacity on the target visual","handlingStrategy":"validation","validationCode":"if (brush is BitmapCacheBrush && brush.Opacity != 1.0) throw new InvalidOperationException(\"BitmapCacheBrush does not support custom Opacity\");","typeGuard":"bool supportsOpacity(Brush b) => b is not BitmapCacheBrush;","tryCatchPattern":"try { cacheBrush.Opacity = value; }\ncatch (InvalidOperationException) { element.Opacity = value; /* apply elsewhere */ }","preventionTips":["Leave BitmapCacheBrush.Opacity at its default 1.0","Apply opacity on the Target visual or hosting element instead","Review brush property assignments when migrating from other brush types"],"tags":["wpf","brush","unsupported-operation","opacity"],"backgroundTag":"invalid-argument-value","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"}