How to rotate a WPF window?

Is it possible to rotate the WPF window 45 degrees using xaml?

+6
source share
2 answers

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

If you really need it:
You cannot rotate a normal WPF window. See: Rotate Window

You will need to create a borderless window and provide it with an interface. See Designing Non-Client WPF Areas for Custom Window Frames.

To view with a rotating window:
Installation:

  • The AllowTransparency property is true.
  • WindowStyle - None to remove a chrome window
  • background to transparent

Include a border (or any value like a rectangle, circle, ellipse, etc.) as the contents of the window and the following border properties:

  • white background (or any opaque color)
  • rotate the transformation and
  • smaller size (to fit when rotating in a window).

Border will provide a user interface to your window.


Keep in mind the catawas of creating your own borderless window, because for this you need to provide a window interface, for example, minimize, enlarge, close buttons; and some unmanaged code may be required.
In addition, in the code example below, the border should be supported within the window during rotation, otherwise it (and your custom window) will be cropped.

Code example

<Window x:Class="CustomWindowStyle.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" AllowsTransparency="True" WindowStyle="None" Background="Transparent" Title="MainWindow" Height="600" Width="600"> <Border BorderBrush="Green" BorderThickness="2" Background="White" Width="360" Height="360"> <Border.RenderTransform> <RotateTransform Angle="-45" CenterX="180" CenterY="180"/> </Border.RenderTransform> <Grid> <Grid.RowDefinitions> <RowDefinition Height="23" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button Grid.Row="0" Content="X" Height="23" Width="23" Name="button1" HorizontalAlignment="Right" VerticalAlignment="Top" Click="button1_Click"/> <Grid Grid.Row="1"> <!--Main window content goes here--> <TextBlock Text="Main window content goes here" HorizontalAlignment="Center" /> </Grid> </Grid> </Border> </Window> 
+7
source

As far as I know, you cannot rotate the whole window, but you can put everything in the window in a user control and apply the RenderTransform object to the custom control.

Example (somewhat simple):

http://www.codeproject.com/KB/WPF/TransformationsIntro.aspx

- Dan

+1
source

Source: https://habr.com/ru/post/886199/


All Articles