zoukankan      html  css  js  c++  java
  • 用WPF建的IPAD demo (内附下载源码)

    刚学WPF,然后建了一个模拟WPF的小例子,新手上路,内容粗糙。

    这是运行后的结果。

    ipad

    废话不多说,直接上源码:

    <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 &amp; CSS &amp; 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>

    后台代码:

    /// <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));
            }
        }

    无论在哪行哪业,兴趣是最好的老师。

    很多东西都是依葫芦画瓢。

    最近云盘竞争很激烈,受益的还是广大码农。

    源码下载

  • 相关阅读:
    “访问”美术馆
    加分二叉树
    有线电视网
    二叉苹果树
    鬼子进村
    遍历问题
    最大子树和
    FBI树
    求前序遍历
    JS如何实现点击页面内任意的链接均加参数跳转?
  • 原文地址:https://www.cnblogs.com/xiaoni/p/3269726.html
Copyright © 2011-2022 走看看