Share via

LinearGradientBrush Repeat SpreadMethod turns foreground UIElements transparent

Paul Hansen 1 Reputation point
2020-12-22T23:44:38.36+00:00

Using a LinearGradientBrush with a SpreadMethod of Repeat causes foreground elements to become transparent:

50506-spreadmethodrepeatbrusherror.png

   <StackPanel Margin="10">  
       <Grid Width="100" Height="100">  
           <Grid.Background>  
               <LinearGradientBrush MappingMode="Absolute" SpreadMethod="Repeat" EndPoint="20,10">  
                   <GradientStop Offset="4" Color="Blue" />  
                   <GradientStop Color="Red" />  
               </LinearGradientBrush>  
           </Grid.Background>  
           <Rectangle Margin="10" Fill="White" />  
       </Grid>  
     
       <Grid Width="100" Height="100">  
           <Grid.Background>  
               <LinearGradientBrush MappingMode="Absolute" SpreadMethod="Pad" EndPoint="20,10">  
                   <GradientStop Offset="4" Color="Blue" />  
                   <GradientStop Color="Red" />  
               </LinearGradientBrush>  
           </Grid.Background>  
           <Rectangle Margin="10" Fill="White" />  
       </Grid>  
   </StackPanel>  

I found this StackOverflow question with the same issue (simplified it for my example), but no workarounds listed.

(Running Win 10 20H2, OS Build 19042.685)

Developer technologies | Universal Windows Platform (UWP)

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.