- xplorerbar_src.zip
- XPlorerBar_src
- XPlorerBar.DemoApp.sln
- XPlorerBar.DemoApp
- App.xaml
- App.xaml.cs
- Converters
- Extra_BindingMode
- Extra_ThemeManagement
- Images
- codeproject120x60.gif
- Computer16.png
- Copy16.png
- CreateFolder16.png
- Delete16.png
- MailFile16.png
- Move16.png
- MusicOnLine16.png
- MyComputer16.png
- MyDocuments16.png
- MyMusic32.png
- MyNetwork16.png
- MyPictures16.png
- MyPictures32.png
- MyPictures48.png
- NetworkFavorites16.png
- OrderPictures16.png
- PlayAll16.png
- PrintPictures16.png
- PublishFolder16.png
- Rename16.png
- SharedMusic16.png
- ShareFolder16.png
- SlideShow16.png
- MainWindow.xaml
- MainWindow.xaml.cs
- Properties
- Resources
- Images
- Folder16.png
- MyComputer16.png
- NetworkPlaces16.png
- PicturePrint16.png
- PictureTasks32.png
- PictureTasksMono48.png
- PrintsOnline16.png
- SlideShow16.png
- Skins
- XPlorerBar.DemoApp.csproj
- XPlorerBar.Documentation
- XPlorerBarDocumentationProject.shfb
- XPlorerBar.Library
- XPlorerBar.VisualStudio.Design
- xplorerbar_demo.zip
- XPlorerBar_demo
- ZonaTools.XPlorerBar.DemoApp.exe
- ZonaTools.XPlorerBar.dll
- ZonaTools.XPlorerBar.Documentation.chm
|
#region [ Copyright © 2008, Zona-Tools, all rights reserved. ]
/*
*
This source code is licensed under the Code Project Open License (CPOL).
Check out http://www.codeproject.com/info/cpol10.aspx for further details.
*
*/
#endregion
#region [ Using namespaces ]
using Microsoft.Windows.Design.Model;
#endregion
namespace ZonaTools.XPlorerBar.VisualStudio.Design
{
/// <summary>
/// Provides utilities to manipulate items in a ModelItemCollection.
/// </summary>
internal static class ModelItemCollectionHelper
{
#region [ Gets item's parent nested items ]
//===========================================================================
/// <summary>
/// Retrieves the parent's nested items of a specific item.
/// </summary>
/// <param name="item">Item whose brothers and sisters are searched
/// for.</param>
/// <param name="property">Name of the parent's property which enable the
/// nested items retrieval.</param>
/// <returns>Parent's nested items collection.</returns>
//===========================================================================
private static ModelItemCollection GetParentItemsCollection(ModelItem item, string property)
{
//Makes sure the item is valid
if (item == null)
return null;
//Gets item's parent and makes sure it is valid
ModelItem parentItem = item.Parent;
if (parentItem == null)
return null;
//Returns the parent's items collection
return parentItem.Properties[property].Collection;
}
#endregion
#region [ Checks item position in the collection ]
//===========================================================================
/// <summary>
/// Checks if the specified item is the first child of its parent.
/// </summary>
/// <param name="item">Item to check.</param>
/// <param name="property">Name of the parent's property which enable the
/// nested items retrieval.</param>
/// <returns><c>true</c> if the specified item is the first child of its
/// parent; otherwise <c>false</c>.</returns>
//===========================================================================
internal static bool IsItFirstSection(ModelItem item, string property)
{
//Gets the parent items collection
ModelItemCollection parentItemsCollection =
GetParentItemsCollection(item, property);
//Makes sure the item and the parent items collection are valid
if ((item == null) || (parentItemsCollection == null))
return true;
//Checks if item is the first child of its parent
return (parentItemsCollection.IndexOf(item) == 0);
}
//===========================================================================
/// <summary>
/// Checks if the specified item is the last child of its parent.
/// </summary>
/// <param name="item">Item to check.</param>
/// <param name="property">Name of the parent's property which enable the
/// nested items retrieval.</param>
/// <returns><c>true</c> if the specified item is the last child of its
/// parent; otherwise <c>false</c>.</returns>
//===========================================================================
internal static bool IsItLastSection(ModelItem item, string property)
{
//Gets the parent items collection
ModelItemCollection parentItemsCollection =
GetParentItemsCollection(item, property);
//Makes sure the item and the parent items collection are valid
if ((item == null) || (parentItemsCollection == null))
return true;
//Checks if item is the last item of its parent
return (parentItemsCollection.IndexOf(item) == (parentItemsCollection.Count - 1));
}
#endregion
#region [ Moves item in the collection ]
//===========================================================================
/// <summary>
/// Moves (up or down) the specified item in its parent container.
/// </summary>
/// <param name="item">The item to move.</param>
/// <param name="moveUp"><c>true</c> if the item has to move up; otherwise
/// <c>false</c>.</param>
/// <param name="property">Name of the parent's property which enable the
/// nested items retrieval.</param>
//===========================================================================
internal static void MoveItem(ModelItem item, bool moveUp, string property)
{
//Gets the parent items collection
ModelItemCollection parentItemsCollection =
ModelItemCollectionHelper.GetParentItemsCollection(item, property);
//Makes sure the item and the parent items collection are valid
if ((item == null) || (parentItemsCollection == null))
return;
//Gets the index of the specified item in the collection
int index = parentItemsCollection.IndexOf(item);
//Moves the item according to the value of the 'MoveUp' boolean
if (moveUp)
parentItemsCollection.Move(index, index - 1);
else
parentItemsCollection.Move(index, index + 1);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have been developing and managing projects for real-time embedded softwares for eight years. Then, I moved from Paris to the south of France and began to lead a team who was developping Java applications.
My main occupation right now is to continue my journey in the WPF world.
You can check out my blog
here. [
^]