How to rotate a WPF Window?

后端 未结 2 1326
陌清茗
陌清茗 2020-12-17 02:09

Is it possible to rotate a WPF Window by 45 degree, using xaml?

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 02:35

    First question: Why do you want to rotate the whole window?

    If you really need it:
    You can't rotate the normal WPF window. See: Rotate Window

    You will have to create a borderless window and provide a UI to it. See: WPF Non-Client Area Design Techniques For Custom Window Frames

    For rotated window look:
    Set:

    • AllowTransparency property to true.
    • WindowStyle to None to remove window chrome
    • Background to Transparent

    Include a border (or anything meaningful like rectangle, circle, ellipse, etc.) as content of the window and following properties of border:

    • white background (or any non-transparent color)
    • rotate transformation, and
    • smaller size (so as to fit when rotated within the window).

    Border will provide the UI to your window.


    Be aware of cavaets of creating own borderless window, as it requires you to provide the window interface like minimise, maximise, close buttons; and may require some unmanaged code.
    Also, in sample code below, the border when rotated has to be kept within the bounds of the window, otherwise it (and your custom window) will be trimmed.

    Sample code

    
    
            
                
                    
                
                
                    
                        
                        
                    
                    

提交回复
热议问题