Click here to Skip to main content
15,892,298 members
Articles / Desktop Programming / WPF

A (Mostly) Declarative Framework for Building Simple WPF-based Wizards

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
7 Mar 2011LGPL322 min read 19.3K   229   15  
A declarative framework for building WPF wizards.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Olbert.Utilities
{
    /// <summary>
    /// a class of file utilities
    /// </summary>
    public static class FileUtils
    {
        // The TruncatePath method was posted by user Bigsby on the Microsoft social website and is presumably
        // in the public domain. You can read more about it at 
        // http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0d0319ed-ea16-40c3-96c6-664b383b69cb/.
        // Thanx, Bigsby!

        /// <summary>
        /// References a function in the lightweight shell library which intelligently truncates a file path.
        /// </summary>
        /// <param name="pszOut">the returned truncated path</param>
        /// <param name="szPath">the path to truncate</param>
        /// <param name="cchMax">the maximum number of characters allowed in the truncated path</param>
        /// <param name="dwFlags">truncation flags (ignored)</param>
        /// <returns>true if the conversion was successful, false otherwise</returns>
        [DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]
        static extern bool PathCompactPathEx( [Out] StringBuilder pszOut, string szPath, int cchMax, int dwFlags );

        /// <summary>
        /// Intelligently truncates a file path to the specified length
        /// </summary>
        /// <param name="path">the file path to truncate</param>
        /// <param name="length">the maximum acceptable length</param>
        /// <returns>a truncated file path</returns>
        public static string TruncatePath( string path, int length )
        {
            StringBuilder sb = new StringBuilder(length + 1);

            PathCompactPathEx(sb, path, length + 1, 0);

            return sb.ToString();
        }
    }
}

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.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Jump for Joy Software
United States United States
Some people like to do crossword puzzles to hone their problem-solving skills. Me, I like to write software for the same reason.

A few years back I passed my 50th anniversary of programming. I believe that means it's officially more than a hobby or pastime. In fact, it may qualify as an addiction Smile | :) .

I mostly work in C# and Windows. But I also play around with Linux (mostly Debian on Raspberry Pis) and Python.

Comments and Discussions