Complex UI inside ListBoxItem

强颜欢笑 提交于 2019-11-26 08:50:05
Jeff

To answer the overarching question - how to do this in WinForms - I'd suggest the following:

  1. Use a WPF ListBox in your WinForms application, wrapped in an ElementHost. This has its own issues, but I think it's the cleanest way to get the desired effect.

    if that doesn't fit the bill, then

  2. Use a third party control suite that has components which support this (Infragistics and DevExpress both do).

  3. Spin your own derived ListBox control that overrides paint, etc to render the desired content.

To your individual questions:

  1. Is there any way to achieve the same in Windows Forms, all while maintaining separation of concerns between the View and the Application Logic in such a way that if I later wanted to completely redefine the View, I wouldn't have to refactor the entire application?
    In the past, I've used the MVP (model-view-presenter) paradigm with Windows Forms. It works for separating the view from the business logic, albeit not as cleanly as an MVVM approach with WPF. The best advice I can give is: don't put business logic in event handlers.

  2. Does winforms support databinding in such a way that each of my ListBoxItems can be bound to a complex Entity, eventually including an intermediate type conversion from Model data to UI data and back, in such a way that I don't have to write tons of boilerplate code to populate the view and then pass the UI values back into the Model in order to save?
    No. Windows Forms databinding does not support complex data binding. You could implement something yourself via ICustomTypeDescriptor or IBindingSource that can take complex paths and evaluate them for binding purposes...but nothing exists out of the box for this.

  3. What if I wanted to introduce Animations in such a way that the currently SelectedItem would animatedly expand itself into some kind of "Row Details" mode, where you can see a lot of additional information?
    You'd have to roll your own Windows Forms ListBox and ListBoxItems and override the paint operations.

  4. Does winforms support UI Virtualization in such a way that if I have, say 1 million items it doesn't take a lifetime to load the UI, and only render what's visible on screen?
    Not out of the box, but some third party control suites have components that support types of virtualization...but not at all in the same way WPF does.

  5. Say I wanted to introduce complex graphics to the equation. Is winforms rendering hardware-accelerated?
    Windows Forms is based on GDI+. GDI+ is not hardware accelerated: Windows Forms very slow under Windows7?

  6. How do I make all this Resolution Independent in such a way that the ListBox and all its contents stretch to the available window size in order to leverage larger screens while maintaining compatibility with smaller ones?
    You can use Docking and Anchoring in Windows Forms to accomplish this. Or you can add custom event handlers to perform appropriate layout adjustments based on resolution and Window size.

  7. It's been suggested to use the ListView control instead of a regular ListBox, does the ListView provide the ability to add ANY UI into it? can I add Videos for example for each item? or a complex Master/Detail template with Save and edit Buttons?
    This is simplifying...but a ListView is simply a ListBox that supports multiple view types. It is also more limited in terms of databinding. http://blog.gfader.com/2008/09/winforms-listbox-vs-listview.html.

  8. Does winforms provide a consistent and adequate [Document Model][2] that enables the creation of high-fidelity WYSIWYG documents and other types of rich content?
    No. Not at all. Not even a little bit.

In short, if it's an acceptable solution, I'd wrap your WPF ListView in an ElementHost and call it a day.

We did this by using UserControls in a scrollable panel. Prepared a user control which has all the editing control on it. Add them to a scrollable panel with dosk property is set to Top. Implemented the item selection behaviour by watching the focus and click events on the added user control items.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!