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
762 stars 122 forks source link

Persistentsearch as a WPFToolkit autocompletebox replacement ? #17

Closed Coloris closed 6 years ago

Coloris commented 6 years ago

So far I've been using WPF Toolkit Autocompletebox (http://www.broculos.net/2014/04/wpf-autocompletebox-autocomplete-text.html) and was wondering if It would be possible to use the persistent search control as a replacement ?

It seems that the persistentsearch control only accepts a IList as a source, are you planning to extend it to support something like ObservableCollection of custom objects (and maybe a bunch of properties like SelectedItem, SelectedValuePath, DisplayMemberPath etc.)

spiegelp commented 6 years ago

PersistentSearch is a very special use case of an autocomplete. It is not meant to handle generic output. So I am thinking of implementing another control as a generic autocomplete. Many months ago, I implemented one for a private app. However, the user interface was quite tricky. I might start to migrate the code into this open source library.

Coloris commented 6 years ago

That would be awesome ! WPF Toolkit Autocompletebox is kinda outdated and a real pain to style.

Thanks again for your work

Coloris commented 6 years ago

I'vet tried your current Autocomplete control, so far it looks good ! Would you provide a way to make it look a bit smaller (if you compare it with the size of a combobox or of an expander it does not really fit overall) ?

spiegelp commented 6 years ago

@Coloris I extended the API and the templates to enable sizing. Applying the style MaterialDesignAutocompleteDense will render a compact Autocomplete. Furthermore, you can play with the FontSize, Padding and ClearIconSize properties and your item template to get the perfect size.

Please let me know if the changes fit your needs.

Coloris commented 6 years ago

@spiegelp The compact version of AutoComplete is perfect ! I'm in the process of implementing it as a replacement of the Wpf Toolkit autocompletebox.

Here are some possible suggestions that I think would improve this control :

Some little issues :

- Setting the SelectedItem property to null does not clear the selection from the control.

I've also noticed a little bit of lag when the popup vanished after making a selection (my list contains roughly 35 values).

Thanks again for your great work.

Edit : There is no bug in fact with setting the SelectedItem property to null, the issue was on my side sorry.

uPloraX commented 6 years ago

What about keyboard support? Up and down keys for navigation, enter and tab for selecting the selected item or something like this. Would appreciate it đź‘Ť

Coloris commented 6 years ago

Related to my previous suggestion: "Ability to decide whether or not to automatically re-open the list after clearing the selection"

I've found a buggy behavior, here is a way to reproduce it :

  1. Create a tabcontrol composed of let’s say two tabitems
  2. Add an autocomplete control inside each tabitems
  3. Type and select something from the first autocomplete control then clear its selection
  4. Switch back and forth between the second and the first tabitems, the autocomplete popup will open itself automatically without having to focus on it manually.

On a side note, I use Mahapps with MaterialDesignXaml (not for designing the controls, just the Window). Mahapps transition animation between TabItems makes it worse since the control is a bit moved, resulting in a situation where the popup end up in a different location that it should. It is related to the fact that the popup is not attached to the control (same behavior as moving the MainWindow around while leaving the popup open).

spiegelp commented 6 years ago

@Coloris I just handled Window.SizeChanged and Window.LocationChanged to relocate the Popup. Unfortunately, Popup does not update its location according to its PlacementTarget. That's why I handle these window events to update the location.

Concerning animations you need to do some work on your own. You could try to listen to the LayoutUpdated event and call the UpdatePopup method of the Autocomplete.

I will have a look at the TabControl issue this week.

Coloris commented 6 years ago

@spiegelp I've tried your implementation and it works pretty well except with double screen, here is how you can reproduce it :

Move the window while the popup is still open, as soon as the application appears on the second screen, the popup will remains stuck on the first screen until 50% of the MainWindow appears on the second screen (and then trigger the opposite effect of having the popup only on the second screen).

As for the TabControl issue, for now and until you work on it, I've implemented a dirty workaround to set the focus on the TabItem itself (which kind of fix my animation issue)

Thanks for your time.

Edit : Actually this issue exists even on a single screen, see attached picture.

img

spiegelp commented 6 years ago

@Coloris The issue with the tab control is a behavior of WPF. If you select a tab via mouse, WPF sets the focus to the content automatically (see here). So you need to keep your workaround.

The behavoir of the autocomplete popup is caused by WPF too. The popup of a MaterialDesignTheme combo box behaves the same. It will be never cut by screen edges:

2018-08-11_21-53_1

At the moment, I don't know how to resolve the issues.

Coloris commented 6 years ago

@spiegelp Thanks for the heads up!

Native WPF combobox behavior is to close the popup when the focus is lost (so for example by moving the window around) this could be another solution ?

As for the tabcontrol, what about triggering the popup only with mouse and keyboard events (like mousehover, tab etc.) and to autoclose the popup when focus is lost (just like my previous point in fact).

spiegelp commented 6 years ago

@Coloris I changed the behavior of the autocomplete popup with the last commit. The control loses the focus causing the popup to close. Now its behavior is more close to a combobox.