{"record":{"id":"a00f4fc12dba75e3","repo":"dotnet/wpf","slug":"sr-bitmapcachebrush-relativetransformchanged","errorCode":null,"errorMessage":"SR.BitmapCacheBrush_RelativeTransformChanged","messagePattern":"SR\\.BitmapCacheBrush_RelativeTransformChanged","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs","lineNumber":371,"sourceCode":"                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));\n        }\n\n        private ContainerVisual _dummyVisual;\n        \n        private DispatcherOperation _DispatcherLayoutResult;\n        private bool _pendingLayout;        \n        private bool _reentrancyFlag;\n\n        private bool _isAsyncRenderRegistered = false;","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/BitmapCacheBrush.cs#L353-L389","documentation":"BitmapCacheBrush only supports its default (null/Identity) RelativeTransform; any attempt to set a non-default transform is coerced back and throws InvalidOperationException. The library intentionally disallows changing RelativeTransform because bitmap-cache rendering cannot apply an arbitrary relative transform on the MilCore side.","triggerScenarios":"Assigning a Transform to BitmapCacheBrush.RelativeTransform (directly, via binding, animation, or style setter) to any value other than the default (null/Transform.Identity).","commonSituations":"Data-binding or animating RelativeTransform by copying XAML patterns from other brushes (VisualBrush, ImageBrush); applying a RenderTransform-style resource to a BitmapCacheBrush in a template.","solutions":["Remove the RelativeTransform assignment and instead apply the transform to the Visual being cached or to the element's RenderTransform/LayoutTransform.","Use RenderTransform on the BitmapCacheBrush itself or its container instead of RelativeTransform.","If a transform is required relative to the output area, wrap the content in a decorator element that applies the transform."],"exampleFix":"// before\nvar brush = new BitmapCacheBrush(visual);\nbrush.RelativeTransform = new RotateTransform(45);\n\n// after\nvar brush = new BitmapCacheBrush(visual);\nbrush.RenderTransform = new RotateTransform(45);","handlingStrategy":"validation","validationCode":"static bool CanSetRelativeTransform(Transform t) => t == null || t == Transform.Identity;","typeGuard":"static bool IsDefaultTransform(Transform t) => t is null || t == Transform.Identity;","tryCatchPattern":null,"preventionTips":["Never set RelativeTransform on BitmapCacheBrush; use RenderTransform on the brush or the cached visual instead.","When copying brush templates between brush types, audit transform properties for BitmapCacheBrush.","Add a style lint/test that asserts RelativeTransform remains default where BitmapCacheBrush is used."],"tags":["wpf","invalid-operation","brush","transform"],"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"}