Skip to content

FileSelect

JaykeBird edited this page Feb 21, 2023 · 11 revisions

Back to home | Back to Reference | View raw text

FileSelect class

Description

A control that provides a responsive and customizable UI for users to select files on their computer, similar to the " input type="file" " element in HTML.

Diagram

  flowchart LR
  classDef interfaceStyle stroke-dasharray: 5 5;
  classDef abstractStyle stroke-width:4px
  subgraph SolidShineUi
  SolidShineUi.FileSelect[[FileSelect]]
  end
  subgraph System.Windows.Controls
System.Windows.Controls.Control[[Control]]
  end
System.Windows.Controls.Control --> SolidShineUi.FileSelect
Loading

Members

Properties

Public properties

Type Name Methods
bool AllowMultipleFiles
Get or set if multiple files can be selected with the FileSelect. If false, only one file can be selected.
get, set
Brush Background
Get or set the brush used for the background of the control.
get, set
Brush BackgroundDisabledBrush
Get or set the brush used for the background of the control (and button) when the control is disabled.
get, set
Brush BorderBrush
Get or set the brush used for the border around the edges of the control.
get, set
Brush BorderDisabledBrush
Get or set the brush used for the border of the control (and button) when the control is disabled.
get, set
string BrowseButtonText
Get or set the text displayed in the Browse button. The default value is "Browse...".
get, set
Brush ButtonBackground
Get or set the brush used for the background of the Browse button in the control.
get, set
Brush ButtonClickBrush
Get or set the brush used for the background of the Browse button while the mouse is clicking it.
get, set
CornerRadius ButtonCornerRadius
Get or set how much rounding to apply to the Browse button inside the control. Settings the corners to 0 means no rounding is done; straight corners are shown.
get, set
Brush ButtonHighlightBrush
Get or set the brush used for the background of the Browse button while the mouse is over it.
get, set
PlacementDirection ButtonPlacement
Get or set the placement location of the Browse button. The button can be placed on any of the four edges of the control, or it can be hidden entirely.
get, set
ColorScheme ColorScheme
Get or set the color scheme used for this control. The color scheme can quickly apply a whole visual style to your control.
get, set
CornerRadius CornerRadius
Get or set how much rounding to apply to the corners of the control. Setting the corners to 0 means no rounding is done; straight corners are shown.
get, set
bool DisplayFilenames
Get or set if the filenames of the selected files are displayed. If true, then all selected files are displayed in a vertical list (with scrolling if needed).
If false, then only a count is displayed (i.e. "3 file(s) selected").
get, set
string FileFilter
Get or set the file filter used when selecting files. Use semicolons (;) to separate multiple extensions/filters (i.e. *.docx;*.xlsx;*.pptx ). Supports * and ? wildcards like Windows.
get, set
Thickness FileListPadding
Get or set the padding to put around the file list portion of the control (the portion that actually has the files listed).
get, set
ScrollBarVisibility HorizontalScrollBarVisibility
Get or set the appearance of the horizontal scroll bar when displaying the list of filenames. Does nothing if DisplayFilenames is set to false.
get, set
string NoFilesSelectedMessage
Get or set the message displayed when no files have been selected. The default value is "(no files selected)".
get, set
LimitableStringCollection SelectedFiles
Get the list of files selected in this FileSelect. You can add or remove items from the collection, or set the collection's max size via the Capacity property.
get
bool ShowIcon
Get or set if the file icons are shown for selected files.
get, set
ScrollBarVisibility VerticalScrollBarVisibility
Get or set the appearance of the vertical scroll bar when displaying the list of filenames. Does nothing if DisplayFilenames is set to false.
get, set

Methods

Public Static methods

Returns Name
void OnColorSchemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Perform an action when the ColorScheme property has changed. Primarily used internally.

Public methods

Returns Name
void ApplyColorScheme(ColorScheme cs)
Apply a color scheme to this control. The color scheme can quickly apply a whole visual style to the control.
void BrowseFiles()
Display an OpenFileDialog for the user to select files.
void ClearAllSelectedFiles()
Clears all files from the SelectedFiles list. No files are then selected.
void CopyFilenamesToClipboard()
Copy the filenames for all the selected files to the clipboard. Each file path is on its own separate line.
void OpenContainingFoldersOfSelectedFiles()
Open the containing folder in Windows Explorer for each of the selected files. If multiple files are in the same folder, that folder may be opened multiple times.
FileStream``[] OpenFilesForReading()
Create a file stream for each selected file, which can be used for reading the files.
FileStream``[] OpenFilesForWriting()
Create a file stream for each selected file, which can be used for reading or writing the files.
void SelectFiles(...)
Select a file.

Details

Summary

A control that provides a responsive and customizable UI for users to select files on their computer, similar to the " input type="file" " element in HTML.

Inheritance

  • Control

Constructors

FileSelect

public FileSelect()
Summary

Create a new FileSelect control.

Methods

OnColorSchemeChanged

public static void OnColorSchemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Arguments
Type Name Description
DependencyObject d The object containing the property that changed.
DependencyPropertyChangedEventArgs e Event arguments about the property change.
Summary

Perform an action when the ColorScheme property has changed. Primarily used internally.

ApplyColorScheme

public void ApplyColorScheme(ColorScheme cs)
Arguments
Type Name Description
ColorScheme cs The color scheme to apply.
Summary

Apply a color scheme to this control. The color scheme can quickly apply a whole visual style to the control.

ClearAllSelectedFiles

public void ClearAllSelectedFiles()
Summary

Clears all files from the SelectedFiles list. No files are then selected.

BrowseFiles

public void BrowseFiles()
Summary

Display an OpenFileDialog for the user to select files.

CopyFilenamesToClipboard

public void CopyFilenamesToClipboard()
Summary

Copy the filenames for all the selected files to the clipboard. Each file path is on its own separate line.

Exceptions
Name Description
InvalidOperationException No files are currently selected.

OpenContainingFoldersOfSelectedFiles

public void OpenContainingFoldersOfSelectedFiles()
Summary

Open the containing folder in Windows Explorer for each of the selected files. If multiple files are in the same folder, that folder may be opened multiple times.

SelectFiles [1/2]

public void SelectFiles(string file)
Arguments
Type Name Description
string file The full path to the file.
Summary

Select a file.

Remarks

If there is no file at the specified path, it is not selected.

SelectFiles [2/2]

public void SelectFiles(IEnumerable<string> files)
Arguments
Type Name Description
IEnumerable<string> files

OpenFilesForReading

public FileStream OpenFilesForReading()
Summary

Create a file stream for each selected file, which can be used for reading the files.

Exceptions
Name Description
InvalidOperationException No files are currently selected.

OpenFilesForWriting

public FileStream OpenFilesForWriting()
Summary

Create a file stream for each selected file, which can be used for reading or writing the files.

Exceptions
Name Description
InvalidOperationException No files are currently selected.

Properties

ColorScheme

public ColorScheme ColorScheme { get; set; }
Summary

Get or set the color scheme used for this control. The color scheme can quickly apply a whole visual style to your control.

Background

public Brush Background { get; set; }
Summary

Get or set the brush used for the background of the control.

ButtonBackground

public Brush ButtonBackground { get; set; }
Summary

Get or set the brush used for the background of the Browse button in the control.

ButtonHighlightBrush

public Brush ButtonHighlightBrush { get; set; }
Summary

Get or set the brush used for the background of the Browse button while the mouse is over it.

ButtonClickBrush

public Brush ButtonClickBrush { get; set; }
Summary

Get or set the brush used for the background of the Browse button while the mouse is clicking it.

BackgroundDisabledBrush

public Brush BackgroundDisabledBrush { get; set; }
Summary

Get or set the brush used for the background of the control (and button) when the control is disabled.

BorderDisabledBrush

public Brush BorderDisabledBrush { get; set; }
Summary

Get or set the brush used for the border of the control (and button) when the control is disabled.

BorderBrush

public Brush BorderBrush { get; set; }
Summary

Get or set the brush used for the border around the edges of the control.

CornerRadius

public CornerRadius CornerRadius { get; set; }
Summary

Get or set how much rounding to apply to the corners of the control. Setting the corners to 0 means no rounding is done; straight corners are shown.

ButtonCornerRadius

public CornerRadius ButtonCornerRadius { get; set; }
Summary

Get or set how much rounding to apply to the Browse button inside the control. Settings the corners to 0 means no rounding is done; straight corners are shown.

BrowseButtonText

public string BrowseButtonText { get; set; }
Summary

Get or set the text displayed in the Browse button. The default value is "Browse...".

NoFilesSelectedMessage

public string NoFilesSelectedMessage { get; set; }
Summary

Get or set the message displayed when no files have been selected. The default value is "(no files selected)".

ShowIcon

public bool ShowIcon { get; set; }
Summary

Get or set if the file icons are shown for selected files.

ButtonPlacement

public PlacementDirection ButtonPlacement { get; set; }
Summary

Get or set the placement location of the Browse button. The button can be placed on any of the four edges of the control, or it can be hidden entirely.

DisplayFilenames

public bool DisplayFilenames { get; set; }
Summary

Get or set if the filenames of the selected files are displayed. If true, then all selected files are displayed in a vertical list (with scrolling if needed). If false, then only a count is displayed (i.e. "3 file(s) selected").

HorizontalScrollBarVisibility

public ScrollBarVisibility HorizontalScrollBarVisibility { get; set; }
Summary

Get or set the appearance of the horizontal scroll bar when displaying the list of filenames. Does nothing if DisplayFilenames is set to false.

VerticalScrollBarVisibility

public ScrollBarVisibility VerticalScrollBarVisibility { get; set; }
Summary

Get or set the appearance of the vertical scroll bar when displaying the list of filenames. Does nothing if DisplayFilenames is set to false.

FileListPadding

public Thickness FileListPadding { get; set; }
Summary

Get or set the padding to put around the file list portion of the control (the portion that actually has the files listed).

Remarks

This can be used to add some space between the Browse button and the list of files, in situations where the two in contact may lead to undesirable results.

SelectedFiles

public LimitableStringCollection SelectedFiles { get; }
Summary

Get the list of files selected in this FileSelect. You can add or remove items from the collection, or set the collection's max size via the Capacity property.

FileFilter

public string FileFilter { get; set; }
Summary

Get or set the file filter used when selecting files. Use semicolons (;) to separate multiple extensions/filters (i.e. *.docx;*.xlsx;*.pptx ). Supports * and ? wildcards like Windows.

Remarks

If the filter is changed after files have been selected, the existing selected files are not re-run against the new filter. This only applies to files added in afterwards.

AllowMultipleFiles

public bool AllowMultipleFiles { get; set; }
Summary

Get or set if multiple files can be selected with the FileSelect. If false, only one file can be selected.

Remarks

If you want to set a specific max number of files that can be selected, set this to "true" and then set the max value via the SelectedFiles.Capacity property.

Events

ColorSchemeChanged

public event DependencyPropertyChangedEventHandler ColorSchemeChanged
Summary

Raised when the ColorScheme property is changed.

InternalCornerRadiusChanged

protected event DependencyPropertyChangedEventHandler InternalCornerRadiusChanged
Summary

Internal event for handling a property changed. Please view the event that is not prefixed as "Internal".

CornerRadiusChanged

public event RoutedEventHandler CornerRadiusChanged
Summary

Raised when the CornerRadius property is changed.

SelectionChanged

public event RoutedEventHandler SelectionChanged
Summary

Raised when the list of selected files is changed.

InternalAllowMultipleFilesChanged

protected event DependencyPropertyChangedEventHandler InternalAllowMultipleFilesChanged
Summary

Internal event for handling a property changed. Please view the event that is not prefixed as "Internal".

AllowMultipleFilesChanged

public event DependencyPropertyChangedEventHandler AllowMultipleFilesChanged
Summary

Raised when the AllowMultipleFiles property is changed.

Generated with ModularDoc

Clone this wiki locally