WPF Button按鈕模板樣式修改(二)
阿新 • • 發佈:2018-11-01
本章講述:Button模板樣式修改,不顯示邊框,只顯示圖示,點選按鈕圖示動態旋轉;
主要採用採用圖片做背景和資料觸發器,觸發故事板(Storyboard)事件,實現按鈕中圖片按角度旋轉;
<Button Width="30" Height="30"> <Button.Style> <Style TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Viewbox Width="30" Height="30"> <Image x:Name="RefreshImge_ctrl" Source="Pack://application:,,,/Real_WPF;component/Resources/Left/refresh.png" Width="25" Height="25" RenderTransformOrigin="0.5,0.5" Stretch="None"> <Image.RenderTransform> <RotateTransform x:Name="imageRefresh" Angle="0"> </RotateTransform> </Image.RenderTransform> </Image> </Viewbox> <ControlTemplate.Triggers> <DataTrigger Binding="{Binding IsActive}" Value="true"> <DataTrigger.EnterActions> <BeginStoryboard x:Name="sb"> <Storyboard > <DoubleAnimation RepeatBehavior="Forever" Storyboard.TargetName="imageRefresh" Storyboard.TargetProperty="Angle" To="360" Duration="0:0:3"/> </Storyboard> </BeginStoryboard> </DataTrigger.EnterActions> <DataTrigger.ExitActions> <StopStoryboard BeginStoryboardName="sb"/> </DataTrigger.ExitActions> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Button.Style> </Button>
效果圖: