生活随笔
收集整理的這篇文章主要介紹了
WPF 基础控件之 ToggleButton 样式
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
其他基礎(chǔ)控件
1.Window
2.Button
3.CheckBox
4.ComboBox
5.DataGrid
6.DatePicker
7.Expander
8.GroupBox
9.ListBox
10.ListView
11.Menu
12.PasswordBox
13.TextBox
14.RadioButton
ToggleButton ?實現(xiàn)下面的效果
1)ToggleButton來實現(xiàn)動畫;
<ResourceDictionary.MergedDictionaries><ResourceDictionary?Source="../Themes/Basic/ControlBasic.xaml"/><ResourceDictionary?Source="../Themes/Basic/Animations.xaml"/></ResourceDictionary.MergedDictionaries><Style?TargetType="{x:Type?ToggleButton}"?BasedOn="{StaticResource?ControlBasicStyle}"><Setter?Property="Focusable"?Value="False"?/><Setter?Property="Cursor"?Value="Hand"/><Setter?Property="Template"><Setter.Value><ControlTemplate?TargetType="{x:Type?ToggleButton}"><Border?x:Name="PART_Border"Width="40"Height="20"Background="{DynamicResource?BaseSolidColorBrush}"CornerRadius="10"><Ellipse?x:Name="PART_Ellipse"?Width="16"?Height="16"Margin="2,0"VerticalAlignment="Center"?HorizontalAlignment="Left"Fill="{DynamicResource?WindowForegroundColorBrush}"><Ellipse.RenderTransform><TranslateTransform/></Ellipse.RenderTransform></Ellipse><VisualStateManager.VisualStateGroups><VisualStateGroup?x:Name="CheckStates"><VisualState?x:Name="Checked"><Storyboard><DoubleAnimation?Storyboard.TargetName="PART_Ellipse"Storyboard.TargetProperty="(Ellipse.RenderTransform).(TranslateTransform.X)"?To="20"?Duration="00:00:.3"EasingFunction="{StaticResource?CubicEaseInOut}"/></Storyboard></VisualState><VisualState?x:Name="Unchecked"><Storyboard><DoubleAnimation?Storyboard.TargetName="PART_Ellipse"Storyboard.TargetProperty="(Ellipse.RenderTransform).(TranslateTransform.X)"?To="0"?Duration="00:00:.3"EasingFunction="{StaticResource?CubicEaseInOut}"/></Storyboard></VisualState><VisualState?x:Name="Indeterminate"?/></VisualStateGroup></VisualStateManager.VisualStateGroups></Border><ControlTemplate.Triggers><Trigger?Property="IsChecked"?Value="True"><Setter?Property="Background"?TargetName="PART_Border"?Value="{DynamicResource?PrimaryNormalSolidColorBrush}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
2)Styles.ToggleButton.xaml 代碼如下;
<WrapPanel?Margin="0,10"><ToggleButton/><ToggleButton?Margin="10,0"?IsEnabled="False"/><ToggleButton?IsChecked="True"/></WrapPanel>
Nuget Install-Package WPFDevelopers.Minimal
[1][2]
技術(shù)群:添加小編微信并備注進(jìn)群
小編微信:mm1552923 ??
公眾號:dotNet編程大全? ??
參考資料
[1]
GitHub: https://github.com/WPFDevelopersOrg
[2]
Gitee: https://gitee.com/WPFDevelopersOrg
總結(jié)
以上是生活随笔為你收集整理的WPF 基础控件之 ToggleButton 样式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。