A WPF File Selection control
March 14th, 2008
This is a pretty simple user control, which allows you to display a file dialog to open or save files. Its look can be easily adjusted, and it provides built-in truncation of the file string to a predefined length if necessary. Here’s the XAML for the above sample control:
<files:FileSelector x:Name="openFileSelector" Mode="Open" MaxDisplayLength="50" Height="24" Width="400" />
The TextBlock in the screenshot which displays the full file path was simply bound to the control’s FileName dependency property:
<TextBlock Text="{Binding ElementName=openFileSelector, Path=FileName}" />
The control does not provide too many extension or styling points – the idea is that you just copy it into your solution, adjust the styling of the control’s contents (Border, Button etc.) and be on your way. The source comes with a small sample project – enjoy 🙂