WPF 滑动按钮
WPF怎么做一个左右滑动的按钮 WPF 滑动按钮 --------------------编程问答-------------------- http://www.cnblogs.com/lhx880619/archive/2011/12/26/2302657.html帮你顶 --------------------编程问答-------------------- ToggleButton 样式模板。滑块可以用一个Border位移动画来实现,用触发器来触发这个位移动画。 --------------------编程问答-------------------- 大侠,能不能帮写一个例子啊,我刚开始学WPF,急用这个,多谢了 --------------------编程问答--------------------
你这个我看过了,不行,你这个是点击的效果,我要拖动按钮的效果,像iphone开关那样,按钮在中间,向左拖就是开,向右拖动就是关 --------------------编程问答--------------------
大侠,能不能帮写一个例子啊,我刚开始学WPF,急用这个,多谢了 --------------------编程问答--------------------
--------------------编程问答-------------------- 忘了说要加个引用
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
<Style x:Key="SliderToggleButton" TargetType="{x:Type ToggleButton}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<ControlTemplate.Resources>
<Storyboard PresentationOptions:Freeze="True" x:Key="ToggleOn">
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="SlidingBorder">
<EasingThicknessKeyFrame KeyTime="0:0:0.1" Value="15,0,0,0"/>
<EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="30,0,0,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
<Storyboard PresentationOptions:Freeze="True" x:Key="ToggleOff">
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="SlidingBorder">
<EasingThicknessKeyFrame KeyTime="0:0:0.1" Value="0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="4" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Grid Grid.Column="1" Width="Auto" Background="{x:Null}">
<Border BorderBrush="#FF9DA2A4" BorderThickness="1" CornerRadius="1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="1"/>
<GradientStop Color="#FF858688"/>
<GradientStop Color="#FFDBDCDD" Offset="0.112"/>
<GradientStop Color="#FFAAABAD" Offset="0.04"/>
<GradientStop Color="#FFCACBCC" Offset="0.08"/>
<GradientStop Color="#FFFEFEFE" Offset="0.149"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<TextBlock TextWrapping="Wrap" Text="关" d:LayoutOverrides="Width, Height" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,10,0"/>
<TextBlock TextWrapping="Wrap" Text="开" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0"/>
<Border x:Name="SlidingBorder" BorderBrush="Black" BorderThickness="1" Width="30" HorizontalAlignment="Left" CornerRadius="1" Background="{TemplateBinding Background}">
<Border BorderThickness="1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#00000000" Offset="0"/>
<GradientStop Color="#7FFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</Border>
</Grid>
<Border x:Name="DisabledBorder" BorderBrush="{x:Null}" BorderThickness="1" Grid.ColumnSpan="2" CornerRadius="1" Background="White" Opacity="0" IsHitTestVisible="False"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true"/>
<Trigger Property="IsChecked" Value="true">
<Trigger.ExitActions>
<BeginStoryboard x:Name="ToggleOff_BeginStoryboard" Storyboard="{StaticResource ToggleOff}"/>
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ToggleOn}"/>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
<Setter Property="Opacity" TargetName="DisabledBorder" Value="0.35"/>
</Trigger>
<Trigger SourceName="SlidingBorder" Property="IsMouseOver" Value="True">
<Setter TargetName="SlidingBorder" Property="BorderBrush" Value="#FFFFE8A3"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" Value="#FF2F63FF"/>
</Style>
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" --------------------编程问答--------------------
我刚才看到一个这样的例子,你看看改改能不能用http://www.cnblogs.com/lanymy/archive/2013/05/20/3088516.html
补充:.NET技术 , C#