wpf 一个仿iphone滑动开关

今天闲来无事,做个防iphone的滑动开关玩玩,美工底子比较差,不好看大家多多包涵。

效果如图,主要是一个dayview和monthview切换的按钮。

刚刚学习wpf 所以做的方法可能比较土。闲话不说上代码

前台xaml代码

"_20111210_Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeChanged="Window_SizeChanged" Loaded="Window_Loaded"
Title="MainWindow" Height="350" Width="525">




"Horizontal">
"{StaticResource normal}" x:Name="DaySwitcher" MouseLeftButtonUp="DaySwitcher_MouseLeftButtonUp">

"5" BottomLeft="5"/>

"Center" VerticalAlignment="Center" Foreground="#FF444242">
Day


"{StaticResource selected}" x:Name="MonthSwitcher" MouseLeftButtonUp="MonthSwitcher_MouseLeftButtonUp">

"5" BottomRight="5"/>

"Center" VerticalAlignment="Center">
Month



在资源里定义了两个style 一个叫normal 一个叫selected

然后就是单击切换事件

后台处理代码比较简单

private void DaySwitcher_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Border b = sender as Border;
b.Style = this.FindResource("selected") as Style;
MonthSwitcher.Style = this.FindResource("normal") as Style;

}

private void MonthSwitcher_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Border b = sender as Border;
b.Style = this.FindResource("selected") as Style;
DaySwitcher.Style = this.FindResource("normal") as Style;
}




转载于:https://www.cnblogs.com/lhx880619/archive/2011/12/26/2302657.html

你可能感兴趣的:(wpf 一个仿iphone滑动开关)