|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis is for anyone looking for a WPF Sortable
Points of InterestWell, I think I am going to just generalize on a lot of the code because the references above do a great job of explaining how each piece works. I have many comments in the code as well. I wanted to point out that these solutions are not exactly what I had in mind, but they work well for now. Of course, unless you wanted to customize the Right now, I am just customizing the The main problems were trying to "share" the Left mouse button events with the These two classes, GroupSortModeListView ClassWith this class, you can turn on and off Grouping by right clicking for the "Allow Grouping" Context menu. This will allow the Properties
Important Methods
GroupSortListView ClassWith this class the first thing you will notice is there is no Grouping mode. That is because Grouping is always on - as is the Sorting. The big downfall this way is that the columns you have sorting and grouping enabled, your column resizing and reordering doesn't work along with the " DependencyProperties
Important Methods
Using the CodeThere are 4 main parts to this app. First are the Designer controls which deal with the custom visual designer items on the Here is how I set up the custom <MyListView:GroupSortModeListView x:Name="sortableListView1" AllowDrop="False"
HorizontalAlignment="Stretch" Grid.Row="1"
Margin="0,0,0,0" VerticalAlignment="Stretch"
IsSynchronizedWithCurrentItem="True"
GroupSortModeListViewColumnHeaderSortedAscendingStyle=
"UpArrowHeaderStyle"
GroupSortModeListViewColumnHeaderSortedDescendingStyle=
"DownArrowHeaderStyle"
GroupSortModeListViewColumnHeaderNotSortedStyle="NoArrowHeaderStyle">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType=
"{x:Type GroupItem}">
<Expander IsExpanded="True"
BorderThickness="0,0,0,1">
<Expander.Header>
<DockPanel>
<TextBlock FontWeight="Bold"
Text="{Binding Path=Name}" Margin="5,0,0,0"
Width="100"/>
<TextBlock FontWeight="Bold"
Text="{Binding Path=ItemCount}"/>
<TextBlock FontWeight="Bold" Text=" Items"/>
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
<MyListView:GroupSortModeListView.View>
<GridView>
<MyListView:GroupSortGridViewColumn Width="93" Header="Print Report">
<MyListView:GroupSortGridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Print" Height="40" Width="80"
HorizontalAlignment="Center" />
</DataTemplate>
</MyListView:GroupSortGridViewColumn.CellTemplate>
</MyListView:GroupSortGridViewColumn>
<MyListView:GroupSortGridViewColumn Width="70" Header="First Name"
DisplayMemberBinding="{Binding FirstName}" />
<MyListView:GroupSortGridViewColumn Width="70" Header="Last Name"
SortPropertyName="Version"
DisplayMemberBinding="{Binding LastName}"/>
<MyListView:GroupSortGridViewColumn Width="95" Header="Project Number"
SortPropertyName="ProjectNumber"
DisplayMemberBinding="{Binding ProjectNumber}"/>
<MyListView:GroupSortGridViewColumn Width="100"
Header="Project Quantity"
SortPropertyName="NumberOfProjects"
DisplayMemberBinding="{Binding NumberOfProjects}"/>
<MyListView:GroupSortGridViewColumn Width="120"
Header="Project Sequence"
SortPropertyName="ProjectsSequenceNumber"
GroupPropertyName="ProjectsSequenceNumber"
DisplayMemberBinding="{Binding ProjectsSequenceNumber}"/>
<MyListView:GroupSortGridViewColumn Width="100" Header="Employee Dept"
SortPropertyName="EmployeeDept" GroupPropertyName="EmployeeDept"
DisplayMemberBinding="{Binding EmployeeDept}"/>
</GridView>
</MyListView:GroupSortModeListView.View>
</MyListView:GroupSortModeListView>
There is also some styling involved of course. Canvas/ListView CommunicationEverything on the Grouping and Sorting side is packaged and handled by the private void HookupDesignerCanvasRemoveGroupEvent()
{
if (!RemoveGroupEventHookedup)
{
//find the DesignerCanvas used and attach to its "RemoveGroup" event!!
DesignerCanvas dc = FindVisualDescendantByType<DesignerCanvas>
(this as DependencyObject)
as DesignerCanvas;
dc.RemoveGroup += new RemoveGroupHandler(dc_RemoveGroup);
RemoveGroupEventHookedup = true;
}
}
And the private UIElement SendRemoveGroupEvent(UIElement element)
{
DesignerItem item;
if (element is DesignerItem)
{
item = element as DesignerItem;
//need to find the descendant of type TextBlock here!!!
TextBlock tb = FindVisualDescendantByType<TextBlock>(item);
//tb.Name contains the groupName we need to remove the group
//with this event to the window!!!
RemoveGroup(tb.Name);//Send Event
return item;
}
return null;
}
This The Running the AppThe ConclusionThis is a good working solution to has both sorting and drag and drop grouping on the Revision History
|
|||||||||||||||||||||||||||||||||||||||||||||||