{"record":{"id":"7321f4d0ec4bc3fa","repo":"dotnet/wpf","slug":"sr-bitmapcachebrush-transformchanged","errorCode":null,"errorMessage":"SR.BitmapCacheBrush_TransformChanged","messagePattern":"SR\\.BitmapCacheBrush_TransformChanged","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs","lineNumber":362,"sourceCode":"        {\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);\n            }\n            return null;\n        }\n\n        private static void StaticInitialize(Type typeofThis)\n        {             \n            OpacityProperty.OverrideMetadata(typeofThis, new IndependentlyAnimatedPropertyMetadata(1.0, propertyChangedCallback: null, CoerceOpacity));\n            TransformProperty.OverrideMetadata(typeofThis, new UIPropertyMetadata(null, propertyChangedCallback: null, CoerceTransform));\n            RelativeTransformProperty.OverrideMetadata(typeofThis, new UIPropertyMetadata(null, propertyChangedCallback: null, CoerceRelativeTransform));","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs#L344-L380","documentation":"BitmapCacheBrush does not support a Transform other than the default (null); the CoerceTransform coercion callback throws whenever a Transform is assigned. Transforms must be applied to the cached content or the rendering element, not the brush.","triggerScenarios":"Setting BitmapCacheBrush.Transform to any Transform instance (e.g. TranslateTransform, RotateTransform) in code, XAML (<BitmapCacheBrush><BitmapCacheBrush.Transform>...</...>), or via binding/animation.","commonSituations":"Developers porting brush code from TileBrush/ImageBrush (which support Transform) to BitmapCacheBrush and carrying over the Transform assignment.","solutions":["Remove the Transform assignment from BitmapCacheBrush","Apply the transform to the Target visual or to the element using the brush (RenderTransform)","If a transform on the cached rendering is required, restructure so the transform is baked into the cached visual"],"exampleFix":"// before\nvar brush = new BitmapCacheBrush { Target = visual, Transform = new TranslateTransform(10, 0) };\n// after\nvar brush = new BitmapCacheBrush { Target = visual };\nvisual.RenderTransform = new TranslateTransform(10, 0);","handlingStrategy":"validation","validationCode":"if (brush is BitmapCacheBrush && brush.Transform != null) throw new InvalidOperationException(\"BitmapCacheBrush does not support Transform\");","typeGuard":"bool supportsTransform(Brush b) => b is not BitmapCacheBrush;","tryCatchPattern":"try { cacheBrush.Transform = t; }\ncatch (InvalidOperationException) { targetVisual.RenderTransform = t; /* apply elsewhere */ }","preventionTips":["Never assign Transform to BitmapCacheBrush","Apply transforms to the Target visual or the element's RenderTransform","Audit brush setups copied from TileBrush/ImageBrush usage"],"tags":["wpf","brush","unsupported-operation","transform"],"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"}