使用SilverLight构建插件式应用程序(六)
2008-10-23 11:43:40 来源:WEB开发网3:显示指定页码的内容:
//
Uri uri = System.Windows.Browser.HtmlPage.Document.DocumentUri;
string host = uri.AbsoluteUri;
host = host.Substring(0, host.Length - uri.LocalPath.Length);
string servicePath = "/Services/WSNotes.svc";
string serviceUri = host + servicePath;
//
WSNotesClient ws = new WSNotesClient(new System.ServiceModel.BasicHttpBinding(), new System.ServiceModel.EndpointAddress(serviceUri));
ws.GetNotesByPageCompleted += (o, e) =>
{
if (e.Error == null)
{
ObservableCollection<NotesInfo> notesInfo = e.Result;
int itemCount = notesInfo.Count;
NotesPage page = new NotesPage();
for (int iItem = 0; iItem < itemCount; iItem++)
{
NotesItem item = new NotesItem();
Thickness thicknessi = new Thickness();
thicknessi.Top = 5;
thicknessi.Bottom = 5;
item.Margin = thicknessi;
item.notesTitle.Text = notesInfo[iItem].Title;
item.notesText.Text = notesInfo[iItem].Content;
item.AuthorName.Text = notesInfo[iItem].UserName;
item.AuthorImage.Source = ResourceHelper.GetBitmap("Resources/Images/self.png", this.GetType().Namespace);
page.panelPageItem.Children.Add(item);
}
Thickness thickness = new Thickness();
thickness.Top = 10;
thickness.Bottom = 10;
page.Margin = thickness;
page.PageFooter.Text = pageNumber.ToString();
this.txtPageNumber.Text = pageNumber.ToString();
this.panelPages.Children.Clear();
this.panelPages.Children.Add(page);
}
//如果在xaml界面直接使用这两个属性,程序运行就会报错
//在这个地方设定没有错误
ScrollPages.SetValue(Grid.RowProperty, 1);
ScrollPages.SetValue(Grid.ColumnProperty, 1);
};
ws.GetNotesByPageAsync(pageNumber,PageSize);
4:控制翻页的状态
string tag = ((Button)sender).Tag.ToString();
if (tag == "First")
{
PageNumber = 1;
}
else if (tag == "Prview")
{
PageNumber = PageNumber - 1; ;
}
else if (tag == "Next")
{
PageNumber = PageNumber + 1; ;
}
else if (tag == "Last")
{
PageNumber = PageCount;
}
else if (tag == "Goto")
{
int tmp=PageNumber;
if (int.TryParse(this.txtPageNumber.Text, out tmp))
{
PageNumber = tmp;
}
else
{
MessageBox.Show("你输入的页码不是整数,请重新输入","提示",MessageBoxButton.OK);
}
}
DataLoad(PageNumber);
至此,整个留言显示完成,如果用户需要留言,请先注册登陆。下一个Blog写如何填写留言。
演示地址:www.cuface.cn
Tags:使用 SilverLight 构建
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接