Click here to Skip to main content
15,887,683 members
Articles / Desktop Programming / WPF

Extend OpenFileDialog and SaveFileDialog Using WPF

Rate me:
Please Sign up or sign in to vote.
4.90/5 (23 votes)
16 Jun 2015CPOL9 min read 188.6K   6.3K   71  
Customize OpenFileDialog and SaveFileDialog using a WPF Window
// Copyright © Decebal Mihailescu 2010
// Some code was obtained by reverse engineering the PresentationFramework.dll using Reflector

// All rights reserved.
// This code is released under The Code Project Open License (CPOL) 1.02
// The full licensing terms are available at http://www.codeproject.com/info/cpol10.aspx
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE. IT CAN BE DISTRIBUTED FREE OF CHARGE AS LONG AS THIS HEADER 
// REMAINS UNCHANGED.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Runtime.InteropServices;

namespace WpfCustomFileDialog
{
    public class WindowAddOnBase : Window, IWindowExt
    {// to be used as here: http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx
        //WPF: Inheriting from custom class instead of Window
        System.Windows.Interop.HwndSource _source;
        IFileDlgExt _parentDlg;
        #region IWindowExt Members
        public System.Windows.Interop.HwndSource Source
        {
            set
            {_source = value;} 
            
        }

        public IFileDlgExt ParentDlg
        {
            set { _parentDlg = value; }
            get { return _parentDlg; }
        }
        #endregion
        protected override Size ArrangeOverride(Size arrangeBounds)
        {

            if (Height > 0 && Width > 0)
            {
                arrangeBounds.Height = this.Height;
                arrangeBounds.Width = this.Width;
            }
            return base.ArrangeOverride(arrangeBounds);
        }
       
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Decebal Mihailescu is a software engineer with interest in .Net, C# and C++.

Comments and Discussions