Precise OpacityMask

后端 未结 4 1059
青春惊慌失措
青春惊慌失措 2021-02-04 10:14

Suppose I need to set an opacity mask on a WPF control that highlights a portion of it in precise position (suppose a 50x50 square at (50;50) position). To do that I create a Dr

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 10:42

    One workaround that may be more ideal than your current one would be to simply apply the OpacityMask at a higher level. Using this demo code for example, you could remove the mask from the Border and apply it to the Window instead. With a bit of tweaking it fits properly:

    
      
        
          
            
              
                
              
            
            
              
                
              
            
          
        
      
    
    

    You would have to write some code to move the mask when the Window is resized, and for that reason you may be better off generating the mask dynamically in the code-behind.

    My question for you is, why do you need to handle geometries that go outside the bounds of your Canvas?

提交回复
热议问题