Use CollectionViewSource to sort and group data in XAML. : CollectionViewSource « Windows Presentation Foundation « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » Windows Presentation Foundation » CollectionViewSource 
16.105.1.Use CollectionViewSource to sort and group data in XAML.
<Window x:Class="WpfApplication1.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
  xmlns:src="clr-namespace:WpfApplication1"
  xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework" 
  Title="CollectionViewSourceSample">

  <Window.Resources>

    <src:Places x:Key="places"/>

    <CollectionViewSource Source="{StaticResource places}" x:Key="cvs">
      <CollectionViewSource.SortDescriptions>
        <scm:SortDescription PropertyName="CityName"/>
      </CollectionViewSource.SortDescriptions>
      <CollectionViewSource.GroupDescriptions>
        <dat:PropertyGroupDescription PropertyName="State"/>
      </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

  </Window.Resources>
  <DockPanel>
    <ListBox ItemsSource="{Binding Source={StaticResource cvs}}" DisplayMemberPath="CityName" Name="lb">
      <ListBox.GroupStyle>
        <x:Static Member="GroupStyle.Default"/>
      </ListBox.GroupStyle>
    </ListBox>
  </DockPanel>
</Window>

//File:Window.xaml.vb

Imports System.Windows
Imports System.Collections.ObjectModel

Namespace WpfApplication1

  Public Partial Class Window1
    Inherits Window
    Public Sub New()
      InitializeComponent()
    End Sub


  End Class

  Public Class Place
    Private name As String

    Private m_state As String

    Public Property CityName() As String
      Get
        Return name
      End Get
      Set
        name = value
      End Set
    End Property

    Public Property State() As String
      Get
        Return m_state
      End Get
      Set
        m_state = value
      End Set
    End Property

    Public Sub New()
      Me.name = ""
      Me.m_state = ""
    End Sub

    Public Sub New(name As String, state As String)
      Me.name = name
      Me.m_state = state
    End Sub
  End Class

  Public Class Places
    Inherits ObservableCollection(Of Place)
    Public Sub New()
      Add(New Place("A""WA"))
      Add(New Place("B""WA"))
      Add(New Place("C""WA"))
    End Sub
  End Class
End Namespace
WPF Use Collection View Source To Sort And Group Data In X A M L
16.105.CollectionViewSource
16.105.1.Use CollectionViewSource to sort and group data in XAML.Use CollectionViewSource to sort and group data in XAML.
16.105.2.Apply Custom Grouping to a CollectionApply Custom Grouping to a Collection
16.105.3.Filter Data in a Collection, Set the Filter property to a FilterEventHandlerFilter Data in a Collection, Set the Filter property to a FilterEventHandler
16.105.4.Set DisplayMemberPath for ItemsControlSet DisplayMemberPath for ItemsControl
16.105.5.Wrap collection based resource in a CollectionViewSourceWrap collection based resource in a CollectionViewSource
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.