spiegelp / MaterialDesignExtensions

Material Design Extensions is based on Material Design in XAML Toolkit to provide additional controls and features for WPF apps
https://spiegelp.github.io/MaterialDesignExtensions/
MIT License
754 stars 122 forks source link

Assign a OpenFileDialog Filter in code #136

Closed sebaJoSt closed 3 years ago

sebaJoSt commented 3 years ago

var dialog = new MaterialDesignExtensions.Controls.OpenFileDialog(); dialog.Filters = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

Error message: Cannot implicitly convert type 'string' to 'System.Collections.Generic.IList'

I think I'm doing it wrong.

spiegelp commented 3 years ago

@sebaJoSt Assigning a string only works in XAML. In Code you can use the helper behind it like this:

dialog.Filters = MaterialDesignExtensions.Controllers.FileFilterHelper.ParseFileFilters("txt files (*.txt)|*.txt|All files (*.*)|*.*");

Creating a dialog on your own is a little bit tedious. See the demo of the specific helper methods for ease of use.

sebaJoSt commented 3 years ago

Thanks for your support. I got it working but I have another small issue:

OpenFileDialogArguments dialogArgs = new()
            {
                Width = 500,
                Height = 500,
                Filters = "License File|*.lic|All files (*.*)|*.*"
            };
OpenFileDialogResult dialogResult = await OpenFileDialog.ShowDialogAsync("ActivationDialog", dialogArgs);

The open file dialog is shown within a dialog with DialogHost "ActivationDialog". This dialog is hosted by another host (MainWIndow DialogHost) and has a size of around 200 x 200px. Even if I change the Width & Height of OpenFileDialog to larger values, it is limited to the size of the ActivationDialog. However when I wrap the OpenFileControl in a dialog user control by myself, it works.