Browse Source

Add sorting support to WPF ListViews.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4989 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
cf8be1851d
  1. 53
      src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml
  2. 2
      src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml.cs
  3. 9
      src/AddIns/Misc/StartPage/Project/Src/StartPageControl.xaml
  4. 2
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs
  5. 226
      src/Main/Base/Project/Src/Project/Converter/UpgradeView.xaml
  6. 16
      src/Main/Base/Project/Src/TextEditor/Commands/ToolCommands.cs
  7. 65
      src/Main/ICSharpCode.Core.Presentation/ExtensionMethods.cs
  8. 2
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  9. 5
      src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs
  10. 212
      src/Main/ICSharpCode.Core.Presentation/SortableGridViewColumn.cs
  11. 1
      src/Main/ICSharpCode.Core.Presentation/themes/Aero.NormalColor.xaml
  12. 29
      src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml

53
src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml

@ -1,29 +1,52 @@
<UserControl x:Class="ICSharpCode.StartPage.RecentProjectsControl" <?xml version="1.0" encoding="utf-8"?>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <UserControl
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ICSharpCode.StartPage.RecentProjectsControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:core="http://icsharpcode.net/sharpdevelop/core">
xmlns:core="http://icsharpcode.net/sharpdevelop/core"> <StackPanel
<StackPanel Orientation="Vertical"> Orientation="Vertical">
<ListView Name="lastProjectsListView" SelectionMode="Single" MouseDoubleClick="lastProjectsDoubleClick" KeyDown="lastProjectsKeyDown"> <ListView
Name="lastProjectsListView"
SelectionMode="Single"
core:SortableGridViewColumn.SortMode="Automatic"
MouseDoubleClick="lastProjectsDoubleClick"
KeyDown="lastProjectsKeyDown">
<ListView.Resources> <ListView.Resources>
<DataTemplate x:Key="nameCellTemplate"> <DataTemplate
x:Key="nameCellTemplate">
<TextBlock> <TextBlock>
<Hyperlink Tag="{Binding}" Click="listViewHyperlinkClick"> <Hyperlink
<TextBlock Text="{Binding Path=Name}" /> Tag="{Binding}"
Click="listViewHyperlinkClick">
<TextBlock
Text="{Binding Path=Name}" />
</Hyperlink> </Hyperlink>
</TextBlock> </TextBlock>
</DataTemplate> </DataTemplate>
</ListView.Resources> </ListView.Resources>
<ListView.View> <ListView.View>
<GridView> <GridView>
<GridViewColumn CellTemplate="{StaticResource nameCellTemplate}" Header="{core:Localize Global.Name}" /> <core:SortableGridViewColumn
<GridViewColumn DisplayMemberBinding="{Binding Path=LastModification}" Header="{core:Localize StartPage.StartMenu.ModifiedTable}" /> SortBy="Name"
<GridViewColumn DisplayMemberBinding="{Binding Path=Path}" Header="{core:Localize StartPage.StartMenu.LocationTable}" /> CellTemplate="{StaticResource nameCellTemplate}"
Header="{core:Localize Global.Name}" />
<core:SortableGridViewColumn
DisplayMemberBinding="{Binding Path=LastModification}"
Header="{core:Localize StartPage.StartMenu.ModifiedTable}" />
<core:SortableGridViewColumn
DisplayMemberBinding="{Binding Path=Path}"
Header="{core:Localize StartPage.StartMenu.LocationTable}" />
</GridView> </GridView>
</ListView.View> </ListView.View>
</ListView> </ListView>
<StackPanel Orientation="Horizontal" Margin="0,20,0,0"> <StackPanel
<Button Content="{core:Localize StartPage.StartMenu.OpenCombineButton}" Click="openSolutionClick" /> Orientation="Horizontal"
<Button Content="{core:Localize StartPage.StartMenu.NewCombineButton}" Click="newSolutionClick" Margin="8,0,0,0" /> Margin="0,20,0,0">
<Button
Content="{core:Localize StartPage.StartMenu.OpenCombineButton}"
Click="openSolutionClick" />
<Button
Content="{core:Localize StartPage.StartMenu.NewCombineButton}"
Click="newSolutionClick"
Margin="8,0,0,0" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

2
src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.StartPage
{ {
InitializeComponent(); InitializeComponent();
SetBinding(HeaderProperty, new LocalizeExtension("StartPage.StartMenu.BarNameName").CreateBinding()); this.SetValueToExtension(HeaderProperty, new LocalizeExtension("StartPage.StartMenu.BarNameName"));
BuildRecentProjectList(); BuildRecentProjectList();
} }

9
src/AddIns/Misc/StartPage/Project/Src/StartPageControl.xaml

@ -73,11 +73,14 @@
Background="#A8C6E3" Background="#A8C6E3"
Grid.Row="2" Grid.Row="2"
Padding="4,0,4,0" Padding="4,0,4,0"
TextWrapping="Wrap"> TextWrapping="WrapWithOverflow">
Copyright ©2000-2009 Copyright ©2000-2009
<Hyperlink <Hyperlink
NavigateUri="mailto:webmaster@icsharpcode.net">IC#SharpCode</Hyperlink><Run NavigateUri="mailto:webmaster@icsharpcode.net">IC#SharpCode</Hyperlink>
Text="{x:Static gui:AboutSharpDevelopTabPage.LicenseSentence}" /></TextBlock> <Run Text=" "/>
<Run
Text="{x:Static gui:AboutSharpDevelopTabPage.LicenseSentence}" />
</TextBlock>
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</UserControl> </UserControl>

2
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.SharpDevelop.Gui
this.layout = layout; this.layout = layout;
this.Name = descriptor.Class.Replace('.', '_'); this.Name = descriptor.Class.Replace('.', '_');
this.SetBinding(TitleProperty, new StringParseExtension(descriptor.Title).CreateBinding()); this.SetValueToExtension(TitleProperty, new StringParseExtension(descriptor.Title));
placeholder = new TextBlock { Text = this.Title }; placeholder = new TextBlock { Text = this.Title };
this.Content = placeholder; this.Content = placeholder;
this.Icon = PresentationResourceService.GetPixelSnappedImage(descriptor.Icon); this.Icon = PresentationResourceService.GetPixelSnappedImage(descriptor.Icon);

226
src/Main/Base/Project/Src/Project/Converter/UpgradeView.xaml

@ -1,113 +1,119 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<UserControl <UserControl
x:ClassModifier="internal" x:ClassModifier="internal"
x:Class="ICSharpCode.SharpDevelop.Project.Converter.UpgradeView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> x:Class="ICSharpCode.SharpDevelop.Project.Converter.UpgradeView"
<Grid> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<Grid.RowDefinitions> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<RowDefinition xmlns:core="http://icsharpcode.net/sharpdevelop/core">
Height="Auto" /> <Grid>
<RowDefinition <Grid.RowDefinitions>
Height="*" /> <RowDefinition
<RowDefinition Height="Auto" />
Height="Auto" /> <RowDefinition
<RowDefinition Height="*" />
Height="Auto" /> <RowDefinition
</Grid.RowDefinitions> Height="Auto" />
<TextBlock <RowDefinition
Grid.Column="0" Height="Auto" />
Grid.Row="0" </Grid.RowDefinitions>
Margin="8,8,8,4"> <TextBlock
This solution was created using a previous version of SharpDevelop. Grid.Column="0"
You might want to upgrade it so that you can use new language or framework features. Grid.Row="0"
</TextBlock> TextWrapping="WrapWithOverflow"
<ListView Margin="8,8,8,4">
x:Name="listView" This solution was created using a previous version of SharpDevelop.
Grid.Column="0" You might want to upgrade it so that you can use new language or framework features.
Grid.Row="1" </TextBlock>
Margin="8,4,8,4" <ListView
SelectionMode="Multiple" x:Name="listView"
SelectionChanged="ListView_SelectionChanged"> core:SortableGridViewColumn.SortMode="Automatic"
<ListView.View> Grid.Column="0"
<GridView> Grid.Row="1"
<GridViewColumn Margin="8,4,8,4"
Header="Project"> SelectionMode="Multiple"
<GridViewColumn.CellTemplate> SelectionChanged="ListView_SelectionChanged">
<DataTemplate> <ListView.View>
<CheckBox <GridView>
Content="{Binding Name}" <core:SortableGridViewColumn
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" /> SortBy="Name"
</DataTemplate> Header="Project">
</GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
</GridViewColumn> <DataTemplate>
<GridViewColumn <CheckBox
DisplayMemberBinding="{Binding CompilerVersionName}" Content="{Binding Name}"
Header="Compiler Version" /> IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" />
<GridViewColumn </DataTemplate>
DisplayMemberBinding="{Binding TargetFrameworkName}" </GridViewColumn.CellTemplate>
Header="Target Framework" /> </core:SortableGridViewColumn>
</GridView> <core:SortableGridViewColumn
</ListView.View> DisplayMemberBinding="{Binding CompilerVersionName}"
</ListView> Header="Compiler Version" />
<CheckBox <core:SortableGridViewColumn
Content="Select _all" DisplayMemberBinding="{Binding TargetFrameworkName}"
Grid.Row="2" Header="Target Framework" />
Name="selectAllCheckBox" </GridView>
Checked="SelectAllCheckBox_Checked" </ListView.View>
Unchecked="SelectAllCheckBox_Unchecked" </ListView>
HorizontalAlignment="Left" <CheckBox
Margin="10,0,0,0" /> Content="Select _all"
<GroupBox Grid.Row="2"
Grid.Column="0" Name="selectAllCheckBox"
Grid.Row="3" Checked="SelectAllCheckBox_Checked"
HorizontalAlignment="Stretch" Unchecked="SelectAllCheckBox_Unchecked"
VerticalAlignment="Stretch" HorizontalAlignment="Left"
Margin="8,0,8,8" Margin="10,0,0,0" />
Header="Change version of selected projects"> <GroupBox
<Grid Grid.Column="0"
Margin="4"> Grid.Row="3"
<Grid.RowDefinitions> HorizontalAlignment="Stretch"
<RowDefinition VerticalAlignment="Stretch"
Height="Auto" /> Margin="8,0,8,8"
<RowDefinition Header="Change version of selected projects">
Height="Auto" /> <Grid
<RowDefinition Margin="4">
Height="Auto" /> <Grid.RowDefinitions>
</Grid.RowDefinitions> <RowDefinition
<Grid.ColumnDefinitions> Height="Auto" />
<ColumnDefinition <RowDefinition
Width="Auto" /> Height="Auto" />
<ColumnDefinition <RowDefinition
Width="120" /> Height="Auto" />
</Grid.ColumnDefinitions> </Grid.RowDefinitions>
<Label <Grid.ColumnDefinitions>
Content="Convert selected _projects to:" <ColumnDefinition
Grid.Column="0" Width="Auto" />
Grid.Row="0" <ColumnDefinition
Target="{Binding ElementName=newVersionComboBox}" /> Width="120" />
<ComboBox </Grid.ColumnDefinitions>
Name="newVersionComboBox" <Label
Grid.Column="1" Content="Convert selected _projects to:"
Grid.Row="0" Grid.Column="0"
Height="22" /> Grid.Row="0"
<Label Target="{Binding ElementName=newVersionComboBox}" />
Content="Change _target framework:" <ComboBox
Grid.Column="0" Name="newVersionComboBox"
Grid.Row="1" Grid.Column="1"
Target="{Binding ElementName=newFrameworkComboBox}" /> Grid.Row="0"
<ComboBox Height="22" />
Name="newFrameworkComboBox" <Label
Grid.Column="1" Content="Change _target framework:"
Grid.Row="1" Grid.Column="0"
Height="22" /> Grid.Row="1"
<Button Target="{Binding ElementName=newFrameworkComboBox}" />
Name="convertButton" <ComboBox
Width="90" Name="newFrameworkComboBox"
Height="22" Grid.Column="1"
Content="_Convert" Grid.Row="1"
Grid.Column="0" Height="22" />
Grid.ColumnSpan="2" <Button
Grid.Row="2" /> Name="convertButton"
</Grid> Width="90"
</GroupBox> Height="22"
</Grid> Content="_Convert"
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="2" />
</Grid>
</GroupBox>
</Grid>
</UserControl> </UserControl>

16
src/Main/Base/Project/Src/TextEditor/Commands/ToolCommands.cs

@ -147,20 +147,4 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
} }
} }
public class SplitTextEditor : AbstractMenuCommand
{
public override void Run()
{
IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent;
if (viewContent == null || !(viewContent is ITextEditorControlProvider)) {
return;
}
TextEditorControl textEditorControl = ((ITextEditorControlProvider)viewContent).TextEditorControl;
if (textEditorControl != null) {
textEditorControl.Split();
}
}
}
} }

65
src/Main/ICSharpCode.Core.Presentation/ExtensionMethods.cs

@ -0,0 +1,65 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows;
using System.Windows.Markup;
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// ExtensionMethods that help with WPF.
/// </summary>
public static class ExtensionMethods
{
/// <summary>
/// Sets the value of a dependency property on <paramref name="targetObject"/> using a markup extension.
/// </summary>
/// <remarks>This method does not support markup extensions like x:Static that depend on
/// having a XAML file as context.</remarks>
public static void SetValueToExtension(this DependencyObject targetObject, DependencyProperty property, MarkupExtension markupExtension)
{
if (targetObject == null)
throw new ArgumentNullException("targetObject");
if (property == null)
throw new ArgumentNullException("property");
if (markupExtension == null)
throw new ArgumentNullException("markupExtension");
var serviceProvider = new SetValueToExtensionServiceProvider(targetObject, property);
targetObject.SetValue(property, markupExtension.ProvideValue(serviceProvider));
}
sealed class SetValueToExtensionServiceProvider : IServiceProvider, IProvideValueTarget
{
readonly DependencyObject targetObject;
readonly DependencyProperty targetProperty;
public SetValueToExtensionServiceProvider(DependencyObject targetObject, DependencyProperty property)
{
this.targetObject = targetObject;
this.targetProperty = property;
}
public object GetService(Type serviceType)
{
if (serviceType == typeof(IProvideValueTarget))
return this;
else
return null;
}
public object TargetObject {
get { return targetObject; }
}
public object TargetProperty {
get { return targetProperty; }
}
}
}
}

2
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -67,9 +67,11 @@
<Compile Include="..\GlobalAssemblyInfo.cs"> <Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link> <Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="SortableGridViewColumn.cs" />
<Compile Include="CollapsiblePanel.cs" /> <Compile Include="CollapsiblePanel.cs" />
<Compile Include="ConditionalSeparator.cs" /> <Compile Include="ConditionalSeparator.cs" />
<Compile Include="DropDownButton.cs" /> <Compile Include="DropDownButton.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="GetBitmapExtension.cs" /> <Compile Include="GetBitmapExtension.cs" />
<Compile Include="IOptionBindingContainer.cs" /> <Compile Include="IOptionBindingContainer.cs" />
<Compile Include="IStatusUpdate.cs" /> <Compile Include="IStatusUpdate.cs" />

5
src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs

@ -69,18 +69,19 @@ namespace ICSharpCode.Core.Presentation
public override object ProvideValue(IServiceProvider serviceProvider) public override object ProvideValue(IServiceProvider serviceProvider)
{ {
if (UpdateOnLanguageChange) { if (UpdateOnLanguageChange) {
return CreateBinding().ProvideValue(serviceProvider); Binding binding = new Binding("Value") { Source = this, Mode = BindingMode.OneWay };
return binding.ProvideValue(serviceProvider);
} else { } else {
return this.Value; return this.Value;
} }
} }
[Obsolete("Use ExtensionMethods.SetValueToExtension instead of directly fetching the binding from this extension")]
public Binding CreateBinding() public Binding CreateBinding()
{ {
return new Binding("Value") { Source = this, Mode = BindingMode.OneWay }; return new Binding("Value") { Source = this, Mode = BindingMode.OneWay };
} }
event System.ComponentModel.PropertyChangedEventHandler ChangedEvent; event System.ComponentModel.PropertyChangedEventHandler ChangedEvent;
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged { public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged {

212
src/Main/ICSharpCode.Core.Presentation/SortableGridViewColumn.cs

@ -0,0 +1,212 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace ICSharpCode.Core.Presentation
{
/// <summary>
/// Allows to automatically sort a grid view.
/// </summary>
public class SortableGridViewColumn : GridViewColumn
{
static readonly ComponentResourceKey headerTemplateKey = new ComponentResourceKey(typeof(SortableGridViewColumn), "ColumnHeaderTemplate");
public SortableGridViewColumn()
{
this.SetValueToExtension(HeaderTemplateProperty, new DynamicResourceExtension(headerTemplateKey));
}
string sortBy;
public string SortBy {
get { return sortBy; }
set {
if (sortBy != value) {
sortBy = value;
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("SortBy"));
}
}
}
#region SortDirection property
public static readonly DependencyProperty SortDirectionProperty =
DependencyProperty.RegisterAttached("SortDirection", typeof(ColumnSortDirection), typeof(SortableGridViewColumn),
new FrameworkPropertyMetadata(ColumnSortDirection.None, OnSortDirectionChanged));
public ColumnSortDirection SortDirection {
get { return (ColumnSortDirection)GetValue(SortDirectionProperty); }
set { SetValue(SortDirectionProperty, value); }
}
public static ColumnSortDirection GetSortDirection(ListView listView)
{
return (ColumnSortDirection)listView.GetValue(SortDirectionProperty);
}
public static void SetSortDirection(ListView listView, ColumnSortDirection value)
{
listView.SetValue(SortDirectionProperty, value);
}
static void OnSortDirectionChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
ListView grid = sender as ListView;
if (grid != null) {
SortableGridViewColumn col = GetCurrentSortColumn(grid);
if (col != null)
col.SortDirection = (ColumnSortDirection)args.NewValue;
Sort(grid);
}
}
#endregion
#region CurrentSortColumn property
public static readonly DependencyProperty CurrentSortColumnProperty =
DependencyProperty.RegisterAttached("CurrentSortColumn", typeof(SortableGridViewColumn), typeof(SortableGridViewColumn),
new FrameworkPropertyMetadata(OnCurrentSortColumnChanged));
public static SortableGridViewColumn GetCurrentSortColumn(ListView listView)
{
return (SortableGridViewColumn)listView.GetValue(CurrentSortColumnProperty);
}
public static void SetCurrentSortColumn(ListView listView, SortableGridViewColumn value)
{
listView.SetValue(CurrentSortColumnProperty, value);
}
static void OnCurrentSortColumnChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
ListView grid = sender as ListView;
if (grid != null) {
SortableGridViewColumn oldColumn = (SortableGridViewColumn)args.OldValue;
if (oldColumn != null)
oldColumn.SortDirection = ColumnSortDirection.None;
SortableGridViewColumn newColumn = (SortableGridViewColumn)args.NewValue;
if (newColumn != null) {
newColumn.SortDirection = GetSortDirection(grid);
}
Sort(grid);
}
}
#endregion
#region SortMode property
public static readonly DependencyProperty SortModeProperty =
DependencyProperty.RegisterAttached("SortMode", typeof(ListViewSortMode), typeof(SortableGridViewColumn),
new FrameworkPropertyMetadata(ListViewSortMode.None, OnSortModeChanged));
public static ListViewSortMode GetSortMode(ListView listView)
{
return (ListViewSortMode)listView.GetValue(SortModeProperty);
}
public static void SetSortMode(ListView listView, ListViewSortMode value)
{
listView.SetValue(SortModeProperty, value);
}
static void OnSortModeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
ListView grid = sender as ListView;
if (grid != null) {
if ((ListViewSortMode)args.NewValue != ListViewSortMode.None)
grid.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(GridViewColumnHeaderClickHandler));
else
grid.RemoveHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(GridViewColumnHeaderClickHandler));
}
}
static void GridViewColumnHeaderClickHandler(object sender, RoutedEventArgs e)
{
ListView grid = sender as ListView;
GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;
if (grid != null && headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding) {
if (headerClicked.Column == GetCurrentSortColumn(grid)) {
if (GetSortDirection(grid) == ColumnSortDirection.Ascending)
SetSortDirection(grid, ColumnSortDirection.Descending);
else
SetSortDirection(grid, ColumnSortDirection.Ascending);
} else {
SetSortDirection(grid, ColumnSortDirection.Ascending);
SetCurrentSortColumn(grid, headerClicked.Column as SortableGridViewColumn);
}
}
}
#endregion
static void Sort(ListView grid)
{
ColumnSortDirection currentDirection = GetSortDirection(grid);
SortableGridViewColumn column = GetCurrentSortColumn(grid);
if (column != null && GetSortMode(grid) == ListViewSortMode.Automatic && currentDirection != ColumnSortDirection.None) {
ICollectionView dataView = CollectionViewSource.GetDefaultView(grid.ItemsSource);
string sortBy = column.SortBy;
if (sortBy == null) {
Binding binding = column.DisplayMemberBinding as Binding;
if (binding != null && binding.Path != null) {
sortBy = binding.Path.Path;
}
}
dataView.SortDescriptions.Clear();
if (sortBy != null) {
ListSortDirection direction;
if (currentDirection == ColumnSortDirection.Descending)
direction = ListSortDirection.Descending;
else
direction = ListSortDirection.Ascending;
dataView.SortDescriptions.Add(new SortDescription(sortBy, direction));
}
dataView.Refresh();
}
}
}
public enum ColumnSortDirection
{
None,
Ascending,
Descending
}
public enum ListViewSortMode
{
/// <summary>
/// Disable automatic sorting when sortable columns are clicked.
/// </summary>
None,
/// <summary>
/// Fully automatic sorting.
/// </summary>
Automatic,
/// <summary>
/// Automatically update SortDirection and CurrentSortColumn properties,
/// but do not actually sort the data.
/// </summary>
HalfAutomatic
}
sealed class ColumnSortDirectionToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Equals(value, parameter) ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
}

1
src/Main/ICSharpCode.Core.Presentation/themes/Aero.NormalColor.xaml

@ -2,6 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.Core.Presentation" xmlns:local="clr-namespace:ICSharpCode.Core.Presentation"
> >
<!-- Colors for DropDownButton and SplitButton -->
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}" Color="#FF3399FF"/> <SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}" Color="#FF3399FF"/>
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}" Color="#FFC2E0FF"/> <SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}" Color="#FFC2E0FF"/>
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:SplitButton}, PressedBackground}" Color="#FF99CCFF"/> <SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:SplitButton}, PressedBackground}" Color="#FF99CCFF"/>

29
src/Main/ICSharpCode.Core.Presentation/themes/generic.xaml

@ -2,10 +2,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.Core.Presentation" xmlns:local="clr-namespace:ICSharpCode.Core.Presentation"
> >
<!-- Colors for DropDownButton and SplitButton -->
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}" Color="#FF0A246A"/> <SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBorder}" Color="#FF0A246A"/>
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}" Color="#FFB6BDD2"/> <SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:DropDownButton}, ActiveBackground}" Color="#FFB6BDD2"/>
<SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:SplitButton}, PressedBackground}" Color="#FF8592B5"/> <SolidColorBrush x:Key="{ComponentResourceKey {x:Type local:SplitButton}, PressedBackground}" Color="#FF8592B5"/>
<!-- Style and Template for DropDownButton -->
<Style TargetType="{x:Type local:DropDownButton}"> <Style TargetType="{x:Type local:DropDownButton}">
<Setter Property="TextElement.Foreground" Value = "{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" /> <Setter Property="TextElement.Foreground" Value = "{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Control.Padding" Value="2,2,2,2"/> <Setter Property="Control.Padding" Value="2,2,2,2"/>
@ -68,6 +70,7 @@
</Setter> </Setter>
</Style> </Style>
<!-- Style and Template for SplitButton -->
<Style TargetType="{x:Type local:SplitButton}"> <Style TargetType="{x:Type local:SplitButton}">
<Setter Property="TextElement.Foreground" Value = "{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" /> <Setter Property="TextElement.Foreground" Value = "{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Control.Padding" Value="2,2,2,2"/> <Setter Property="Control.Padding" Value="2,2,2,2"/>
@ -144,7 +147,8 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<!-- Template for CollapsiblePanel -->
<Style TargetType="{x:Type local:CollapsiblePanel}"> <Style TargetType="{x:Type local:CollapsiblePanel}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -177,6 +181,8 @@
</Setter> </Setter>
</Style> </Style>
<!-- Template for RadioButtonGroup -->
<!-- Necessary because Selector does not have a template by default. -->
<Style TargetType="{x:Type local:RadioButtonGroup}"> <Style TargetType="{x:Type local:RadioButtonGroup}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -199,4 +205,25 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<!-- SortableGridViewColumn.
Displays an up arrow or down arrow in the column header when the grid is sorted using that column.
-->
<local:ColumnSortDirectionToVisibilityConverter x:Key="ColumnSortDirectionToVisibilityConverter"/>
<DataTemplate x:Key="{ComponentResourceKey {x:Type local:SortableGridViewColumn}, ColumnHeaderTemplate}">
<StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
<Path x:Name="upArrow"
Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static local:ColumnSortDirection.Ascending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}"
StrokeThickness = "1"
Fill = "Gray"
Data = "M 5,10 L 15,10 L 10,5 L 5,10"/>
<Path x:Name="downArrow"
Visibility="{Binding Path=Column.SortDirection, ConverterParameter={x:Static local:ColumnSortDirection.Descending}, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumnHeader}}, Converter={StaticResource ColumnSortDirectionToVisibilityConverter}}"
StrokeThickness = "1"
Fill = "Gray"
Data = "M 5,5 L 10,10 L 15,5 L 5,5"/>
</StackPanel>
</DataTemplate>
</ResourceDictionary> </ResourceDictionary>
Loading…
Cancel
Save