WPF (Binding of LinQ)

Source: Internet
Author: User

[Html]
<Window x: Class = "TestOfLinQBinding. MainWindow"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "MainWindow" Height = "350" Width = "525">

<StackPanel Background = "LightBlue">
<ListView x: Name = "listViewStudents"
Height = "143"
Margin = "5">
<ListView. View>
<GridView>
<GridViewColumn Header = "Id" Width = "60"
DisplayMemberBinding = "{Binding Id}"/>
<GridViewColumn Header = "Name" Width = "100"
DisplayMemberBinding = "{Binding Name}"/>
<GridViewColumn Header = "Age" Width = "80"
DisplayMemberBinding = "{Binding Age}"/>

</GridView>
</ListView. View>
</ListView>
<Button Content = "Load" Height = "25" Margin = "5, 0" Click = "Button_Click"/>

</StackPanel>
</Window>

<Window x: Class = "TestOfLinQBinding. MainWindow"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "MainWindow" Height = "350" Width = "525">

<StackPanel Background = "LightBlue">
<ListView x: Name = "listViewStudents"
Height = "143"
Margin = "5">
<ListView. View>
<GridView>
<GridViewColumn Header = "Id" Width = "60"
DisplayMemberBinding = "{Binding Id}"/>
<GridViewColumn Header = "Name" Width = "100"
DisplayMemberBinding = "{Binding Name}"/>
<GridViewColumn Header = "Age" Width = "80"
DisplayMemberBinding = "{Binding Age}"/>

</GridView>
</ListView. View>
</ListView>
<Button Content = "Load" Height = "25" Margin = "5, 0" Click = "Button_Click"/>

</StackPanel>
</Window>
[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. Data;
Using System. Windows. Documents;
Using System. Windows. Input;
Using System. Windows. Media;
Using System. Windows. Media. Imaging;
Using System. Windows. Navigation;
Using System. Windows. Shapes;
 
Namespace TestOfLinQBinding
{
/// <Summary>
/// Interaction logic for MainWindow. xaml
/// </Summary>
Public partial class MainWindow: Window
{
Public MainWindow ()
{
InitializeComponent ();
}
 
Private void Button_Click (object sender, RoutedEventArgs e)
{
List <Student> stuList = new List <Student> ()
{
New Student () {Id = 0, Name = "Tim", Age = 29 },
New Student () {Id = 1, Name = "Tom", Age = 28 },
New Student () {Id = 2, Name = "Kyle", Age = 27 },
New Student () {Id = 3, Name = "Tony", Age = 26 },
New Student () {Id = 4, Name = "Vina", Age = 25 },
New Student () {Id = 5, Name = "Mike", Age = 24}
};
 
This. listViewStudents. ItemsSource = from student in stuList where student. Name. StartsWith ("T") select student;
 
}
}
 
Public class Student
{
Public int Id {get; set ;}
Public String Name {get; set ;}
Public int Age {get; set ;}
}
}

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. Data;
Using System. Windows. Documents;
Using System. Windows. Input;
Using System. Windows. Media;
Using System. Windows. Media. Imaging;
Using System. Windows. Navigation;
Using System. Windows. Shapes;

Namespace TestOfLinQBinding
{
/// <Summary>
/// Interaction logic for MainWindow. xaml
/// </Summary>
Public partial class MainWindow: Window
{
Public MainWindow ()
{
InitializeComponent ();
}

Private void Button_Click (object sender, RoutedEventArgs e)
{
List <Student> stuList = new List <Student> ()
{
New Student () {Id = 0, Name = "Tim", Age = 29 },
New Student () {Id = 1, Name = "Tom", Age = 28 },
New Student () {Id = 2, Name = "Kyle", Age = 27 },
New Student () {Id = 3, Name = "Tony", Age = 26 },
New Student () {Id = 4, Name = "Vina", Age = 25 },
New Student () {Id = 5, Name = "Mike", Age = 24}
};

This. listViewStudents. ItemsSource = from student in stuList where student. Name. StartsWith ("T") select student;

}
}

Public class Student
{
Public int Id {get; set ;}
Public String Name {get; set ;}
Public int Age {get; set ;}
}
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.