wpf-devexpress-dot-xpf-dot-editors-a474cd7a.md
A text editor that allows users to specify a path to a file/folder.
Namespace : DevExpress.Xpf.Editors
Assembly : DevExpress.Xpf.Core.v25.2.dll
NuGet Package : DevExpress.Wpf.Core
[DXLicenseWpf]
public class BrowsePathEdit :
ButtonEdit
<DXLicenseWpf>
Public Class BrowsePathEdit
Inherits ButtonEdit
The BrowsePathEdit displays the specified file’s/folder’s icon, a text box where users can edit the path, and a button that invokes a browse dialog.
Tip
The BrowsePathEdit class inherits its features from the ButtonEdit class.
Refer to the ButtonEdit class description for information on derived features and API.
Use the BaseEdit.EditValue property to specify the editor’s value.
<Window ...
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
<dxe:BrowsePathEdit EditValue="C:\Program Files\"/>
<dxe:BrowsePathEdit EditValue="C:\"/>
Handle the BaseEdit.EditValueChanged event to get a notification when the editor’s value is changed. To validate the new value, handle the BaseEdit.Validate event or use the techniques described in the following help topic: Input Validation.
The BrowsePathEdit displays a path icon if the ShowIcon property is set to true. The PathIcon property returns the displayed icon.
If a user specifies an invalid file path, the BrowsePathEdit displays the invalid path icon:
The following code sample uses the PathIconSelector property to change the icon displayed for folders:
<Window.Resources>
<local:IconSelector x:Key="iconSelector"/>
</Window.Resources>
<!-- ... -->
<dxe:BrowsePathEdit DialogType="Folder" PathIconSelector="{StaticResource iconSelector}">
using DevExpress.Xpf.Editors;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
// ...
public class IconSelector : IPathIconSelector {
public ImageSource Select(string path) {
if (Directory.Exists(path))
return new BitmapImage(new System.Uri("pack://application:,,,/Open_16x16.png"));
return null;
}
}
Imports DevExpress.Xpf.Editors
Imports System.IO
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
' ...
Public Class IconSelector
Inherits IPathIconSelector
Public Function [Select](ByVal path As String) As ImageSource
If Directory.Exists(path) Then Return New BitmapImage(New System.Uri("pack://application:,,,/Open_16x16.png"))
Return Nothing
End Function
End Class
The following code sample uses the CustomPathIcon event to change the icon displayed if a user enters an invalid path:
<dxe:BrowsePathEdit DialogType="Folder" CustomPathIcon="OnCustomPathIcon">
using DevExpress.Xpf.Editors;
using System.IO;
using System.Windows.Media.Imaging;
// ...
void OnCustomPathIcon(object sender, PathIconEventArgs e) {
if (!Directory.Exists(e.Path))
e.Icon = new BitmapImage(new System.Uri("pack://application:,,,/Warning_16x16.png"));
e.Handled = true;
}
Imports DevExpress.Xpf.Editors
Imports System.IO
Imports System.Windows.Media.Imaging
' ...
Private Sub OnCustomPathIcon(ByVal sender As Object, ByVal e As PathIconEventArgs)
If Not Directory.Exists(e.Path) Then e.Icon = New BitmapImage(New System.Uri("pack://application:,,,/Warning_16x16.png"))
e.Handled = True
End Sub
The CustomPathIcon event has a higher priority than the PathIconSelector property.
Use the DialogType property to specify the type of the dialog invoked when a user clicks the Browse button or you call the ShowDialog method. The BrowsePathEdit can invoke the following dialogs:
FileOpenThe dialog that allows users to select a file (OpenFileDialog).FileSaveThe dialog that allows users to save a file with the specified name and type (SaveFileDialog).FolderThe dialog that allows users to select a folder (FolderBrowserDialog).
The BrowsePathEdit raises the following events when a user opens or closes the browse dialog:
DialogOpeningAllows you to cancel the open dialog operation or use the DialogParameters class members to customize the invoked dialog.DialogClosedAllows you to get whether a user selects a file/folder or closes the dialog.
The following code sample specifies the dialog’s initial file name, extension, and folder:
e.Handled property to true to apply settings.<dxe:BrowsePathEdit DialogType="FileSave" DialogOpening="OnDialogOpening">
using DevExpress.Xpf.Editors;
using System;
// ...
void OnDialogOpening(object sender, DialogOpeningEventArgs e) {
e.DialogParameters.FileName = "NewFile";
e.DialogParameters.DefaultExt = "txt";
e.DialogParameters.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
e.Handled = true;
}
Imports DevExpress.Xpf.Editors
Imports System
'...
Private Sub OnDialogOpening(ByVal sender As Object, ByVal e As DialogOpeningEventArgs)
e.DialogParameters.FileName = "NewFile"
e.DialogParameters.DefaultExt = "txt"
e.DialogParameters.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
e.Handled = True
End Sub
Users can drop files/folders onto the BrowsePathEdit to specify the file/folder path. To enable this functionality, set the editor’s AllowDrop property to true. In this case, the BrowsePathEdit displays the following placeholder text: "Drop a file/folder here".
Use the BaseEdit.NullText property to specify custom placeholder text.
Refer to the following help topic for more information: Appearance Customization.
Show 12 items
Object DispatcherObject DependencyObject Visual UIElement FrameworkElement Control BaseEdit TextEditBase TextEdit ButtonEdit BrowsePathEdit
See Also