silverlight 数据邦定并实现页面传值

silverlight 数据邦定并实现页面传值,第1张

概述范型类提供数据源 using System; using System.Collections.Generic; using System.Linq; namespace CustomerUriApp {     public class Customers     {         public List<Customer> GetAllCustomers()         {       

范型类提供数据源

using System;
using System.Collections.Generic;
using System.linq;

namespace CustomerUriApp
{
    public class Customers
    {
        public List<Customer> GetAllCustomers()
        {
            List<Customer> c = new List<Customer>();
            c.Add(new Customer()
                { CustomerID = 1,
                Companyname = "Microsoft" });
            c.Add(new Customer()
                { CustomerID = 2,
                Companyname = "Google" });
            c.Add(new Customer()
                { CustomerID = 3,
                Companyname = "Apple" });
            return c;
        }

    

      public Customer GetCustomer(int customerID)
        {
            var customer =
                           from c in GetAllCustomers()
                           where c.CustomerID == customerID
                           select c;

            return customer.First();
        }


    }

    public class Customer
    {
        public int CustomerID { get; set; }
        public string Companyname { get; set; }
    }
}

邦定数据控件

<uriMapper:UriMapPing Uri="Customer/{customerID}"                                        
       MappedUri="/VIEws/CustomerDetails.xaml?customerID={customerID}" />

 

<ItemsControl x:name="CustomersList">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel OrIEntation="Horizontal">
                <Hyperlinkbutton FontSize="24"
                            Content="{Binding Companyname}"
                            Tag="{Binding CustomerID}" 
               Click="Hyperlinkbutton_Click" />
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

 页面加载时邦定数据

public Home()
{
    InitializeComponent();
    Loaded += new RoutedEventHandler(Home_Loaded);
}

 

voID Home_Loaded(object sender,RoutedEventArgs e)
{
    Customers c = new Customers();
    CustomersList.ItemsSource = c.GetAllCustomers();
}

 

hyperlinkbutton click 事件

 


private voID Hyperlinkbutton_Click
    (object sender,RoutedEventArgs e)
{
    Hyperlinkbutton hyperlink = sender as Hyperlinkbutton;
    string customerID = hyperlink.Tag.ToString();

    this.NavigationService.Navigate
        (new Uri
            (string.Format("Customer/{0}",customerID),UriKind.relative)); //传递customerID


}

 

  CustomerDetails.xaml Page 接收传递参数

<StackPanel>
    <TextBlock x:name="CustomerID" FontSize="24"></TextBlock>
</StackPanel>

 protected overrIDe voID OnNavigatedTo(NavigationEventArgs e){    CustomerID.Text = this.NavigationContext.queryString["customerID"];}

总结

以上是内存溢出为你收集整理的silverlight 数据邦定并实现页面传值全部内容,希望文章能够帮你解决silverlight 数据邦定并实现页面传值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1025283.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存