#眉標=LINQ #副標=剖析LINQ運作機制(6) #大標= WPF、Windows Form有何不同? #作者=文/圖 黃忠成 ============= 程式1 ================ ============= 程式2 ================ ============= 程式3 .................略............. ================ ============= 程式4 .xaml ..............略 .xaml.cs 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 WpfApplication1 { public partial class Window1 : Window { NorthwindDataContext context = new NorthwindDataContext(); public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { DataContext = from s in context.Customers orderby s.CustomerID select s; } } } ================ ============= 程式5 ...........略............. .........略...... ================ ============= 程式6 .xaml .............. ................ .xaml.cs 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; using System.ComponentModel; using System.Data.Linq; using System.Reflection; namespace LinqWPF1 { public partial class Window1 : Window { private NorthwindDataContext context = new NorthwindDataContext(); private ICollectionView view = null; public Window1() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { DataContext = from s in context.Customers              orderby s.CustomerID select s; view = CollectionViewSource.GetDefaultView(DataContext); } private void Next_Click(object sender, RoutedEventArgs e) { if (!view.MoveCurrentToNext()) view.MoveCurrentToLast(); } private void Prev_Click(object sender, RoutedEventArgs e) { if (!view.MoveCurrentToPrevious()) view.MoveCurrentToFirst(); } } } ================ ============= 程式7 .xaml .............略........