用WPF建的IPAD demo (內(nèi)附下載源碼)
剛學(xué)WPF,然后建了一個(gè)模擬WPF的小例子,新手上路,內(nèi)容粗糙。
這是運(yùn)行后的結(jié)果。
廢話不多說(shuō),直接上源碼:
<Window x:Class="iPad.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:iPad" WindowStyle="None" AllowsTransparency="True" Background="{x:Null}" Title="{DynamicResource Title}" FontFamily="Segoe UI" Width="420" Height="580" Loaded="windowMain_Loaded" MouseLeftButtonDown="windowMain_MouseLeftButtonDown"> <Window.Resources> <sys:String x:Key="Title">All my possessions for a moment of time.</sys:String> <Style x:Key="PageStyle"> <Setter Property="FrameworkElement.Width" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ScrollViewAnimation}}, Path=ActualWidth}" /> <Setter Property="FrameworkElement.Height" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ScrollViewAnimation}}, Path=ActualHeight}" /> </Style> </Window.Resources> <Border Padding="35" Background="Black" BorderBrush="Gainsboro" BorderThickness="5" CornerRadius="10"> <Border> <Border.Background> <ImageBrush ImageSource="Images/iPad.png" /> </Border.Background> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <local:ScrollViewAnimation x:Name="UIScrollView"> <StackPanel Orientation="Horizontal"> <Grid Style="{DynamicResource PageStyle}" TextBlock.FontSize="22" TextBlock.FontWeight="Bold"> <StackPanel Margin="0,10,0,0" TextBlock.Foreground="WhiteSmoke"> <TextBlock x:Name="textBlockDate" HorizontalAlignment="Center">Date</TextBlock> <TextBlock x:Name="textBlockTime" HorizontalAlignment="Center">Time</TextBlock> <TextBlock x:Name="textBlockWeekday" HorizontalAlignment="Center">Weekday</TextBlock> <UniformGrid Margin="0,10,0,0" Columns="3"> <UniformGrid.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Pages/UICommon.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </UniformGrid.Resources> <Image Source="Images/XML.png" /> <Image Source="Images/HTML & CSS & JavaScript.png" /> <Image Source="Images/CSharp.png" /> <Image Source="Images/Asp.Net.png" /> <Image Source="Images/WPF.png" /> <Image Source="Images/Silverlight.png" /> <Image Source="Images/WCF.png" /> <Image Source="Images/WF.png" /> <Image Source="Images/SQL Server.png" /> </UniformGrid> </StackPanel> </Grid> <Grid Style="{DynamicResource PageStyle}"> <DockPanel Margin="15" LastChildFill="True"> <DockPanel DockPanel.Dock="Top"> <Button DockPanel.Dock="Right" MinWidth="40" Click="Button_Click">Go</Button> <TextBox x:Name="textBoxUrl" /> </DockPanel> <Frame x:Name="frameNavigate" Background="White" Opacity="0.3" /> </DockPanel> </Grid> <Grid Style="{DynamicResource PageStyle}"> <Image Margin="30" Source="Images/WPF.png"> <Image.Effect> <DropShadowEffect Color="White" /> </Image.Effect> </Image> </Grid> </StackPanel> </local:ScrollViewAnimation> <WrapPanel Grid.Row="1" Margin="0,10,0,10" HorizontalAlignment="Center" MouseLeftButtonDown="WrapPanel_MouseLeftButtonDown"> <WrapPanel.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Pages/UICommon.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </WrapPanel.Resources> <Ellipse x:Name="PreviewPage" /> <Ellipse x:Name="NextPage" Margin="15,0,0,0" /> </WrapPanel> </Grid> </Border> </Border> </Window>
后臺(tái)代碼:
/// <summary> /// MainWindow.xaml 的交互邏輯 /// </summary> public partial class MainWindow : Window { private DispatcherTimer DispatcherDateTime = new DispatcherTimer(DispatcherPriority.ApplicationIdle); public MainWindow() { InitializeComponent(); } private void windowMain_Loaded(object sender, RoutedEventArgs e) { DispatcherDateTime.Interval = new TimeSpan(0, 0, 1); DispatcherDateTime.Tick += new EventHandler(UpdataDateTime); DispatcherDateTime.Start(); } private void windowMain_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DragMove(); } private void UpdataDateTime(object sender, EventArgs e) { textBlockDate.Text = DateTime.Now.ToString("D"); textBlockTime.Text = DateTime.Now.ToString("T"); textBlockWeekday.Text = DateTime.Now.DayOfWeek.ToString(); } private void WrapPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { switch ((e.Source as Ellipse).Name) { case "NextPage": UIScrollView.ScrollNext(Orientation.Horizontal, 0.5); break; case "PreviewPage": UIScrollView.ScrollPreview(Orientation.Horizontal, 0.5); break; } } private void Button_Click(object sender, RoutedEventArgs e) { frameNavigate.Navigate(new Uri(textBoxUrl.Text)); } }