There is an event click on the button:

void new_button_click(object sender, RoutedEventArgs e) { Button btn = sender as Button; btn.? } 

I want the button to rotate 90 degrees when clicked. How to implement it?

    1 answer 1

    You can do with triggers:

      <Button Width="100" Height="50" Content="bla-bla"> <Button.Style> <Style TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Property="LayoutTransform"> <Setter.Value> <RotateTransform Angle="90"/> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> 

    UPD Render style to window resource:

     <Window.Resources> <ResourceDictionary> <Style TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="IsPressed" Value="True"> <Setter Property="LayoutTransform"> <Setter.Value> <RotateTransform Angle="90"/> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> </ResourceDictionary> </Window.Resources> 

    I want one click - one turn. and I need not all buttons to turn. And certain.

    Specify in the style x:Key="styleBtn" and then specify the style on the buttons you want to rotate:

     <Button Style="{StaticResource styleBtn}"/> 
    • No, I do not have a fixed number of buttons. The user decides how many he will have. I need a universal solution on c #, because they are generated at the user's request :) - Saint
    • @Saint: Well, render the style in ResourceDictionary . - VladD
    • but you can not write something like: btn.RotateTransformation = (0.5, 0.5); don't swear, took everything out of your head :) - Saint
    • @ S.Kost and how to render it, tell me. you are welcome? - Saint
    • @Saint: Yes, but not necessary. Well this is not WinForms, break the writing so. - VladD