silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了silverlight 数据邦定并实现页面传值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

范型类提供数据源 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 数据邦定并实现页面传值所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。