Rotate a ListBox

image_pdfimage_print


   
      

<Window x:Class="WPFTransformations.Rotate"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Rotate Transform" Height="350" Width="300">
  <Grid>
        <StackPanel Margin="8">
            <TextBlock Height="25" Width="100"/>
            <ListBox Height="100" Width="200" BorderThickness="2">
                <ListBoxItem Content="Item 1" Height="22"/>
                <ListBoxItem Content="Item 2" Height="22"/>
                <ListBoxItem Content="Item 3" Height="22"/>
                <ListBoxItem Content="Item 4" Height="22"/>
                <ListBox.RenderTransform>
                   <RotateTransform
                        Angle="{Binding ElementName=sliderAngle, Path=Value}" 
                        CenterX="{Binding ElementName=sliderCenterX, Path=Value}" 
                        CenterY="{Binding ElementName=sliderCenterY, Path=Value}"/>
                </ListBox.RenderTransform>
            </ListBox>

            <TextBlock Height="65" Width="100"/>
            <Grid HorizontalAlignment="Center" Margin="2">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="110"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Text="Angle:"/>
                <Slider Grid.Row="0" Grid.Column="1" Name="sliderAngle" Maximum="360" Minimum="-360"/>
                <TextBox Grid.Row="0" Grid.Column="2" Text="{Binding ElementName=sliderAngle, Path=Value}"/>

                <TextBlock Grid.Row="2" Grid.Column="0" Text="Center Y:"/>
                <Slider Grid.Row="2" Grid.Column="1" Name="sliderCenterY"/>
                <TextBox Grid.Row="2" Grid.Column="2" Text="{Binding ElementName=sliderCenterY, Path=Value}"/>

            </Grid>
        </StackPanel>
        <StackPanel Margin="8">
            <TextBlock Height="25" Width="100"/>
            <Rectangle Height="100" Width="200" Stroke="Red" Fill="Red" Opacity=".05"/>
        </StackPanel>
    </Grid>
</Window>