XAML<Window x:Class="cvsFormulaOne.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework" xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" xmlns:local="clr-namespace:cvsFormulaOne" Title="MainWindow" Height="350" Width="600" Loaded="Window_Loaded"><Window.Resources><DataTemplate x:Key="hdrTemplate"><StackPanel><TextBlock Text="{Binding Path=Name}" Margin="0,5" FontSize="22" FontStyle="Italic"><TextBlock.Background><RadialGradientBrush><GradientStop Color="Black" Offset="0" /><GradientStop Color="#47E5D9D9" Offset="0.729" /></RadialGradientBrush></TextBlock.Background></TextBlock></StackPanel></DataTemplate><local:F1DB x:Key="f1DB"/><ObjectDataProvider x:Key="odpF1" ObjectType="{x:Type local:F1DB}" MethodName="getTeams"></ObjectDataProvider><CollectionViewSource x:Key="cvsF1" Source="{Binding Source={StaticResource odpF1}}"><CollectionViewSource.SortDescriptions><scm:SortDescription PropertyName="noChampionships" Direction="Ascending"/></CollectionViewSource.SortDescriptions><CollectionViewSource.GroupDescriptions><dat:PropertyGroupDescription PropertyName="EngineMaker"/> </CollectionViewSource.GroupDescriptions></CollectionViewSource></Window.Resources><Grid><Grid.RowDefinitions><RowDefinition Height="*"></RowDefinition><RowDefinition Height="3*"></RowDefinition></Grid.RowDefinitions><StackPanel Orientation="Horizontal"><Border Margin="5,5"><StackPanel><Label>No of Driver Championship</Label><StackPanel><RadioButton GroupName="rbgNoChamp" Click="RadioButton_Click"
Tag="ASC" IsChecked="true">Ascending</RadioButton><RadioButton GroupName="rbgNoChamp"
Click="RadioButton_Click" Tag="DESC">Descending</RadioButton></StackPanel></StackPanel><Border.Background><RadialGradientBrush><GradientStop Color="Black" Offset="0" /><GradientStop Color="#47E5D9D9" Offset="0.729" /></RadialGradientBrush></Border.Background></Border><Border Margin="5,5" MinWidth="80"><StackPanel><CheckBox HorizontalAlignment="Center" Margin="0,5" Name="chkMakerFilter"
Checked="chkMakerFilter_Checked" Unchecked="chkMakerFilter_Unchecked">Filter</CheckBox><ComboBox Name="cbxMaker" VerticalAlignment="Top"
HorizontalAlignment="Stretch" Margin="5,0"
SelectionChanged="cbxMaker_SelectionChanged" IsEnabled="False"></ComboBox></StackPanel><Border.Background x:Uid="hi"><LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="Black" Offset="0" /><GradientStop Color="#47E5D9D9" Offset="0.729" /></LinearGradientBrush></Border.Background></Border><Border Margin="5,5" MinWidth="80"><StackPanel><CheckBox HorizontalAlignment="Center" Margin="0,5" Name="chkTeamNameTxtFilter"
Checked="chktxtTeamNameFilter_Checked"
Unchecked="chktxtTeamNameFilter_Unchecked">Filter</CheckBox><TextBox Name="txtTeamNameFilter" VerticalAlignment="Top"
MinWidth="50" HorizontalContentAlignment="Center"
HorizontalAlignment="Stretch" Margin="5,0"
TextChanged="txtTeamNameFilter_TextChanged" IsEnabled="False"></TextBox></StackPanel><Border.Background><LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="Black" Offset="0" /><GradientStop Color="#47E5D9D9" Offset="0.729" /></LinearGradientBrush></Border.Background></Border><Border Margin="5,5" MinWidth="80"><StackPanel><CheckBox HorizontalAlignment="Center" Margin="0,5" Name="chkGroupFilter"
Checked="chkGroupFilter_Checked" Unchecked="chkGroupFilter_Unchecked"
Content="Group by No Constructors"></CheckBox><CheckBox HorizontalAlignment="Center" Margin="5"
Name="chkGroupMakerFilter" Checked="chkGroupMakerFilter_Checked"
Unchecked="chkGroupMakerFilter_Unchecked" Content="Group by Teams"></CheckBox></StackPanel><Border.Background><LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="Black" Offset="0" /><GradientStop Color="#47E5D9D9" Offset="0.729" /></LinearGradientBrush></Border.Background></Border></StackPanel><Border Background="Red" CornerRadius="8" Grid.Row="1"><ListBox Name="lbxData" Margin="5" ItemsSource="{Binding Source={StaticResource cvsF1}}"><ListBox.GroupStyle><GroupStyle HeaderTemplate="{StaticResource hdrTemplate}"/></ListBox.GroupStyle></ListBox></Border></Grid></Window>
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; namespace cvsFormulaOne { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { CollectionViewSource cvs; public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { // retrieve CollectionViewSource resource from XAML cvs = this.Resources["cvsF1"] as CollectionViewSource; // fill combobox with EngineMakers of F1Teams cbxMaker.ItemsSource = Enum.GetNames(typeof(Makers)); // set first Maker as selected if >0 Makers if (cbxMaker.Items.Count > 0) cbxMaker.SelectedIndex = 0; cvs.Filter += new FilterEventHandler(cvs_Filter); } private void RadioButton_Click(object sender, RoutedEventArgs e) { // retrieve the CollectionViewSource from the resources section of XAML string sortOrder = ((RadioButton)sender).Tag as String; // query Radiobutton for sort order cvs.SortDescriptions.Clear(); // clear out existing sorting // apply new sort order if (sortOrder == "ASC") cvs.SortDescriptions.Add(new SortDescription("noDriverChampionships",
ListSortDirection.Ascending)); else cvs.SortDescriptions.Add(new SortDescription("noDriverChampionships",
ListSortDirection.Descending)); } void cvs_Filter(object sender, FilterEventArgs e) { F1Team f1 = e.Item as F1Team; if (chkMakerFilter.IsChecked == true) { //Makers m = (Makers)cbxMaker.SelectedItem; Makers m = (Makers)Enum.Parse(typeof(Makers), cbxMaker.SelectedItem.ToString(), true); if (f1.EngineMaker == m) e.Accepted = true; else e.Accepted = false; } else if (chkTeamNameTxtFilter.IsChecked == true) { if (f1.TeamName.ToLower().StartsWith(txtTeamNameFilter.Text.ToLower())) e.Accepted = true; else e.Accepted = false; } } private void cbxMaker_SelectionChanged(object sender, SelectionChangedEventArgs e) { cvs.View.Refresh(); chkTeamNameTxtFilter.IsChecked = false; } private void txtTeamNameFilter_TextChanged(object sender, TextChangedEventArgs e) { cvs.View.Refresh(); } private void chkTeamNameTxtFilter_Checked(object sender, RoutedEventArgs e) { txtTeamNameFilter.IsEnabled = true; chkMakerFilter.IsChecked = false; chkGroupFilter.IsChecked = false; txtTeamNameFilter.Focus(); cvs.View.Refresh(); } private void chkTeamNameTxtFilter_Unchecked(object sender, RoutedEventArgs e) { txtTeamNameFilter.IsEnabled = false; } private void chkGroupMakerFilter_Checked(object sender, RoutedEventArgs e) { chkTeamNameTxtFilter.IsChecked = false; chkMakerFilter.IsChecked = false; chkGroupFilter.IsChecked = false; cvs.GroupDescriptions.Clear(); cvs.SortDescriptions.Clear(); cvs.SortDescriptions.Add(new SortDescription("TeamName", ListSortDirection.Ascending)); cvs.SortDescriptions.Add(new SortDescription("noDriverChampionships", ListSortDirection.Descending)); cvs.GroupDescriptions.Add(new PropertyGroupDescription("EngineMaker")); } private void chkGroupMakerFilter_Unchecked(object sender, RoutedEventArgs e) { cvs.GroupDescriptions.Clear(); cvs.SortDescriptions.Clear(); cvs.View.Refresh(); } private void chkGroupFilter_Unchecked(object sender, RoutedEventArgs e) { cvs.GroupDescriptions.Clear(); cvs.SortDescriptions.Clear(); cvs.View.Refresh(); } private void chkGroupFilter_Checked(object sender, RoutedEventArgs e) { chkTeamNameTxtFilter.IsChecked = false; chkMakerFilter.IsChecked = false; cvs.GroupDescriptions.Clear(); cvs.SortDescriptions.Clear(); cvs.SortDescriptions.Add(new SortDescription("noChampionships", ListSortDirection.Ascending)); cvs.SortDescriptions.Add(new SortDescription("noDriverChampionships", ListSortDirection.Ascending)); noChampionships pogc = new noChampionships(); cvs.GroupDescriptions.Add(new PropertyGroupDescription("noChampionships", new noChampionships())); } private void chkMakerFilter_Checked(object sender, RoutedEventArgs e) { cbxMaker.IsEnabled = true; this.chkTeamNameTxtFilter.IsChecked = false; chkGroupFilter.IsChecked = false; cvs.View.Refresh(); } private void chkMakerFilter_Unchecked(object sender, RoutedEventArgs e) { cbxMaker.IsEnabled = false; this.chkTeamNameTxtFilter.IsChecked = true; cvs.View.Refresh(); } private void chktxtTeamNameFilter_Checked(object sender, RoutedEventArgs e) { txtTeamNameFilter.IsEnabled = true; chkMakerFilter.IsChecked = false; chkGroupFilter.IsChecked = false; txtTeamNameFilter.Focus(); cvs.View.Refresh(); } private void chktxtTeamNameFilter_Unchecked(object sender, RoutedEventArgs e) { txtTeamNameFilter.IsEnabled = false; } } }
class noChampionships : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo
culture) { // establish range of values and assign incoming value to one of three divisions int minPrev, maxPrev, thirdInterval, inValue; int[] ranges = F1DB.getRangenoChampionships(); inValue = (int)value; minPrev = ranges[0]; maxPrev = ranges[1]; thirdInterval = (maxPrev - minPrev) / 3; if (inValue < thirdInterval) return string.Format("{0}-{1}", minPrev, minPrev + thirdInterval); if (inValue < thirdInterval * 2) return string.Format("{0}-{1}", minPrev + thirdInterval,
minPrev + thirdInterval * 2); return String.Format("{0}-{1}", minPrev + thirdInterval * 2, maxPrev); } public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
CLASSES class noChampionships : IValueConverter { public object Convert(object value, Type targetType, object parameter,And what I'd like to know how would u put an image into the header example the manufacturer icon. Can anyone help me, cheers.
System.Globalization.CultureInfo culture) { // establish range of values and assign incoming value to one of three divisions int minPrev, maxPrev, thirdInterval, inValue; int[] ranges = F1DB.getRangenoChampionships(); inValue = (int)value; minPrev = ranges[0]; maxPrev = ranges[1]; thirdInterval = (maxPrev - minPrev) / 3; if (inValue < thirdInterval) return string.Format("{0}-{1}", minPrev, minPrev + thirdInterval); if (inValue < thirdInterval * 2) return string.Format("{0}-{1}", minPrev + thirdInterval, minPrev +
thirdInterval * 2); return String.Format("{0}-{1}", minPrev + thirdInterval * 2, maxPrev); } public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace cvsFormulaOne { public enum Makers { Toyota, Ford, Jaguar, Mercedes, Renualt, Lotus }; public class F1Team { public Makers EngineMaker { get; set; } public string TeamName { get; set; } public int noDriverChampionships { get; set; } public int noChampionships { get; set; } public override string ToString() { return String.Format("{0} Engine \t{1} \t(Won {2} Driver and Won {3} Constructor Champioships).",
EngineMaker, TeamName, noDriverChampionships, noChampionships); } } // end class } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.ObjectModel; namespace cvsFormulaOne { public class F1DB { private static ObservableCollection<F1Team> F1Teams = new ObservableCollection<F1Team>(); public static ObservableCollection<F1Team> getTeams() { return F1Teams; } static F1DB() { // populate with some F1Teams objects F1Teams.Add(new F1Team { EngineMaker = Makers.Toyota, TeamName = "Toyota F1",
noDriverChampionships = 0, noChampionships = 0}); F1Teams.Add(new F1Team { EngineMaker = Makers.Ford, TeamName = "Steward F1",
noDriverChampionships = 0, noChampionships = 0 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Jaguar, TeamName = "Jaguar F1",
noDriverChampionships = 0, noChampionships = 0 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Mercedes, TeamName = "Vodafone McLaren",
noDriverChampionships = 12, noChampionships = 8 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Mercedes, TeamName = "Mercedes F1",
noDriverChampionships = 2, noChampionships = 0 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Mercedes, TeamName = "Force India",
noDriverChampionships = 0, noChampionships = 0 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Renualt, TeamName = "Red Bull Racing",
noDriverChampionships = 3, noChampionships = 3 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Renualt, TeamName = "Williams F1",
noDriverChampionships = 5, noChampionships = 5 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Renualt, TeamName = "Caterham F1",
noDriverChampionships = 0, noChampionships = 0 }); F1Teams.Add(new F1Team { EngineMaker = Makers.Lotus, TeamName = "Lotus F1",
noDriverChampionships = 2, noChampionships = 2 }); } // Adds another F1Teams to database public static void addCar(F1Team F1) { F1Teams.Add(F1); } public static int[] getRangenoChampionships() { // return min and max of values in db for noChampionships return new int[] { (from F1 in F1Teams select F1.noChampionships).Min(), (from F1 in F1Teams select F1.noChampionships).Max() }; } } // end class }
NB:Anyone who might create this file, and you'll see the ui, I know its a bit odd of a UI, but sorry, not good at create stylish the UI