微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

教你打造Silverlight超酷翻页实例二

 
LeftPage.cs 文件代码  


using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SilverlightClient.TypePage 
{
  
public class LeftPage : Canvas 
  {
    
//定义将在页面显示的元素
    private Image imgPhoto;
    
private Button btnPrevIoUs;
    
private Rectangle RecBorder;
    
private TextBlock PageNum;
    
    
//构造函数
    public LeftPage()
    {
      
//页面的设置
      this.Width = 452;
      
this.Height = 630;
      
this.Background = new SolidColorBrush(Colors.White);
      Canvas.SetLeft(
this0);
      Canvas.SetTop(
this0);
      
//页面边框的设置
      RecBorder = new Rectangle();
      RecBorder.Width 
= 452;
      RecBorder.Height 
= 630;
      Canvas.SetLeft(RecBorder, 
0);//设置页面边框在Canvas中的位置,下同。
      Canvas.SetTop(RecBorder, 0);
      RecBorder.stroke 
= new SolidColorBrush(Colors.Black);
      RecBorder.strokeThicknes
= 0;
      
this.Children.Add(RecBorder);
      
//照片的设置
      imgPhoto = new Image();
      imgPhoto.Width 
= 450;
      imgPhoto.Height 
= 600;
      Canvas.SetLeft(imgPhoto, 
1);
      Canvas.SetTop(imgPhoto, 
1);
      
this.Children.Add(imgPhoto);
      
//“前一页”按钮的设置
      btnPrevIoU= new Button();
      btnPrevIoUs.Width 
= 150;
      btnPrevIoUs.Height 
= 20;
      btnPrevIoUs.Content 
= "<< 前一页";
      btnPrevIoUs.HorizontalContentAlignment 
= HorizontalAlignment.Center;
      btnPrevIoUs.VerticalContentAlignment 
= VerticalAlignment.Center;
      btnPrevIoUs.Cursor 
= Cursors.Hand;
      Canvas.SetLeft(btnPrevIoUs, 
151);
      Canvas.SetTop(btnPrevIoUs, 
605);
      
this.Children.Add(btnPrevIoUs);
      
//页码文本的设置
      PageNum = new TextBlock();
      PageNum.Width 
= 100;
      PageNum.Height 
= 20;
      PageNum.Text 
= "00 / 00";
      PageNum.TextAlignment 
= TextAlignment.Left;
      PageNum.VerticalAlignment 
= VerticalAlignment.Center;
      PageNum.FontFamily 
= new FontFamily("Comic sans MS");
      Canvas.SetLeft(PageNum, 
10);
      Canvas.SetTop(PageNum, 
607);
      
this.Children.Add(PageNum);
    }
    
//设置图片路径
    public void setterimgPhoto(string path)
    {
      BitmapImage btm 
= new BitmapImage();
      btm.UriSource 
= new Uri(path, UriKind.Relative);
      imgPhoto.source 
= btm;
    }
    
//设置按钮是否可见
    public void setterdisplayBtnPrevIoUs(bool YesNo)
    {
      
if (YesNo)
      {
        btnPrevIoUs.Visibility 
= Visibility.Visible;
      }
      
else {
        btnPrevIoUs.Visibility 
= Visibility.Collapsed;
      }
    }
    
//设置页码
    public void setterPageNumber(string currentPageNum, string TotalPageNum) {
        PageNum.Text 
= currentPageNum + " / " + TotalPageNum;
    }
    
//返回按钮单击事件关联
    public Button getbtnPrevIoUs()
    {
      
return btnPrevIoUs;
    }

  }
}
 
 
RightPage.cs 文件代码
 


using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SilverlightClient.TypePage 
{
  
public class RightPage : Canvas 
  {
    
//定义将在页面显示的元素
    private Image imgPhoto;
    
private Button btnNext;
    
private Rectangle RecBorder;
    
private TextBlock PageNum;
    
    
//构造函数
    public RightPage()
    {
      
//页面的设置
      this.Width = 452;
      
this.Height = 630;
      
this.Background = new SolidColorBrush(Colors.White);
      Canvas.SetLeft(
this0);//设置页面边框在Canvas中的位置,下同。
      Canvas.SetTop(this0);
      Canvas.SetTop(RecBorder, 
1);
      
this.Children.Add(imgPhoto);
      
//“后一页”按钮的设置
      btnNext = new Button();
      btnNext.Width 
= 150;
      btnNext.Height 
= 20;
      btnNext.Content 
= "后一页 >>";
      btnNext.HorizontalContentAlignment 
= HorizontalAlignment.Center;
      btnNext.VerticalContentAlignment 
= VerticalAlignment.Center;
      btnNext.Cursor 
= Cursors.Hand;
      Canvas.SetLeft(btnNext, 
151);
      Canvas.SetTop(btnNext, 
605);
      
this.Children.Add(btnNext);
      
//页码文本的设置
      PageNum = new TextBlock();
      PageNum.Width 
= 100;
      PageNum.Height 
= 20;
      PageNum.Text 
= "00 / 00";
      PageNum.TextAlignment 
= TextAlignment.Right;
      PageNum.VerticalAlignment 
= VerticalAlignment.Center;
      PageNum.FontFamily 
= new FontFamily("Comic sans MS");
      Canvas.SetLeft(PageNum, 
340);
      Canvas.SetTop(PageNum, 
607);
      
this.Children.Add(PageNum);
    }
    
//设置图片路径
    public void setterimgPhoto(string path)
    {
        BitmapImage btm 
= new BitmapImage();
        btm.UriSource 
= new Uri(path, UriKind.Relative);
        imgPhoto.source 
= btm;
    }
    
//设置按钮是否可见
    public void setterdisplayBtnNext(bool YesNo)
    {
        
if (YesNo)
        {
            btnNext.Visibility 
= Visibility.Visible;
        }
        
else
        {
            btnNext.Visibility 
= Visibility.Collapsed;
        }
    }
    
//设置页码
    public void setterPageNumber(string currentPageNum, string TotalPageNum)
    {
        PageNum.Text 
= currentPageNum + " / " + TotalPageNum;
    }
    
//返回按钮单击事件关联
    public Button getbtnNext()
    {
        
return btnNext;
    }

  }
}
 
3 、构建应用程序界面
详细的说明请见代码注释。
MainPage.xaml 文件代码  


<UserControl x:Class="SilverlightClient.MainPage"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d
="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local
="clr-namespace:SLMitsuControls;assembly=SLMitsuControls"         
    mc:Ignorable
="d" d:DesignWidth="640" d:DesignHeight="480" Loaded="UserControl_Loaded">
  
<Grid x:Name="LayoutRoot">
      
<Canvas x:Name="layout" Background="White" Width="906" Height="630"
      
 Canvas.Left="0" Canvas.Top="0">
        
<!--显示-->  
        
<Canvas x:Name="canvasBook" Background="White" Width="906" Height="630" Canvas.Left="0"
        
 Canvas.Top="0" Visibility="Collapsed">
            
<local:UCBook x:Name="book" Width="906" Height="630" Canvas.Left="0" Canvas.Top="0" /><!--BookControl-->
        
</Canvas>
        
<!--加载层-->
        
<Canvas x:Name="canvChanging" Width="500" Height="75" Canvas.Left="200" Canvas.Top="250" 
           Visibility
="Collapsed" Background="Transparent">
            
<TextBlock x:Name="changingText" Text="页面加载中

"
 Width="200" Height="30" 
               Canvas.Left
="0" Canvas.Top="0" FontFamily="comic sans ms" FontSize="14"></TextBlock>
            
<ProgressBar x:Name="changingProgressBar" Width="500" Height="30" Canvas.Left="0" 
              Canvas.Top
="30"></ProgressBar>
        
</Canvas>
      
</Canvas>
  
</Grid>
</UserControl>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐