Well I am confused, because didnt find good way to have something like RecyclerView in winforms.
I want to do something like this:
Its pretty easy to make it in Android but now I need same thing in Winforms for Desktop.
What I want to see:
ListView with Panel inside. Panel contains image and multiple labels with different sizes.
What I tried:
1) ObjectListView
Not so bad. Its smooth. But I cannot make it customize it fully. I can place simple controls inside it, but cant make multiple labels one below other.
2) FlowLayoutPanel and just place dynamically panels inside.
With this option I can do everything I want but after adding ~20-30 panels its not smooth anymore. Also I spend too much time for implementing "lazy loading" for it and there are really big problems with making it smooth.
So the question is: can you recommend me better solution than I tried already?
May be its some library or another way of using system resources.
Related
I am trying to find a way to create custom controls which lets the user drag them around on screen. This illustration shows roughly what I'm after:
So, this is basically a node network, where each node can have an arbitrary number of children and exactly one parent node. The connections between the nodes also has to follow them when they move, and bend appropriatly. I would also like all nodes to move when dragging the "canvas" behind them.
I know this is a lot of information, but basically I'm wondering if this is possible (and not too difficult) to achieve with WPF, and if it breaks with the philosophy of WPF to use it in this way. Is there a better way than using WPF for this? I've done a lot of research and can't find much info doing these things with it. Also, what is the most common ways to do this in Windows applications using .NET and C# if this seems way off?
I am learning multi threading in Win Forms using C# and according to sources the best way to achieve this is by invoking the main method from worker threads.
Now this all works good when heavy processing must be done and THEN the GUI is updated.
However I have a scenario where I need to programmatically add lots of controls inside a panel. This may go up to thousands (panel will be scrollable). Hence, since the controls are ultimately being added by the main thread, the program still hangs until this has been completed.
Is there any way around this? Or should I try and use some other control which doesn't require me to instantiate lots of controls simultaneously (as this is obviously a bit heavy).
Basically this panel contains a list together with an icon (depending on the state). Hence I am creating a label for every entry which I do not know if it the ideal way.
By the way I come from the web applications development department... Is there a control similar to a div in .NET? I looked at a rich text box but it doesn't seem to let you add an image in a straightforward way.
Thanks in advance.
You shouldn't have a good reason to add hundreds of controls, let alone thousands. It sounds like you need a custom control and you need to add items to it.
The ListBox or ListView control will work for a basic item but if you want lots of customizability you will have to reinvent the wheel yourself and draw everything manually. It's a lot of work if you need to handle multiselect, scrolling, keyboard shortcuts, etc.
This is the strength of using WPF instead of Winforms since you can easily use the existing ListBox logic and have free range to customize the appearance of the items and even how they are arranged.
WPF has the concept of a virtualizing panel which can perform well even with thousands of items since it doesn't create the UI objects until an item is scrolled to.
I'm trying to create a MainMenu for my application that looks similar to the one used by Mozilla Firefox:
So that it displays over aero glass. I can think of a few ways to do this, except they would be ugly, and probably ruin the experience of the program due to them being hackish.
I'm wondering if there is a way to custom draw the MainMenu control, similar to how you can override the OnPaint method on other controls (which for some reason, MainMenu doesn't have). Or if that is not possible, what sort of hacky ways could I use that wouldn't ruin the UX.
Yes, I'm sure there is a ridiculously easy way to do this in WPF, and I would love to be able to take the time to learn it, but my application is already in a semi-mature stage, and it would be extremely inconvenient to switch to a different UI platform at this point.
I ended up creating my own control that inherits ToolStripMenuItem and overriding OnPaint and drawing the text with DrawThemeTextEx, and using a modified version of the MenuStrip renderer found here that omits the rendering of header text (so it doesn't conflict with DrawThemeTextEx and the background bar of the ToolStrip.
Final product looks like this:
I have an idea for a personal project. And I know one way of accomplishing it in Windows Forms (which I no longer wish to use). Basically I could (in WinForms) just draw everything onto the screen (Form) and then when I need to switch views/states of the application, just redraw the new stuff in the old stuff's place.
But how can we have different states in WPF? Is there a "right" or "proper" way of doing this? Is something like this covered somewhere in the docs?
I'd like to do my own searching, but I have no idea what exactly to look for, and current attempts at finding the right information, so far have yielded no helpful (or even relevant) results.
Any help at all will be greatly appreciated. I am new to WPF, but have been making a lot of progress this past week!
Thank you!
P.S.:
I just thouhght of something. If the solution was to draw what is needed for one screen, and when it is time to display the next screen, just dispose of/hide everything and create/display the new stuff, then how would we get around this? Because we can't/shouldn't change XAML markup at runtime, can/should we? :/
Not sure how you drawn your views/states in WinForms (direct painting on a Graphics object?).
The closest to what you're describing is the VisualStateManager. You can use it to statically define several visual states inside a single XAML and transit between them (using a smooth animation if you want).
If what you've done was show different Forms with Show/ShowDialog(), then the equivalent would be to use different Windows and Show/Hide them.
If you just cleared/added Controls to your form, then you can do just the same in WPF. Most Controls in WPF have a Content or Children property instead of Control.Controls in Forms.
I don't know if I understand what you really want. But here are my thoughts:
You can use several Windows and Show/Hide them accordingly
You can use the Frame/Page functionality in WP (MSDN)
if you really need to you could load your XAML and remove the topmost content in your Window and replace it with the loaded content
You could use the VisualStateGroup functionality to change the appearance of your current window
I think you will be happy with the second solution
I'm building a control that comprises 15x15 = 225 buttons, and needs to be resizable. Because it's a grid, anchoring and docking won't work. I've tried both TableLayoutPanel as well as handling the resize event to manually place and size controls. In both cases, resizing is unacceptably slow. Suspend/Resume Layout in the resize function when I'm manually handling the layout doesn't help.
Is there something fundamental that I can change to speed things up, or is this just a limitation of the native controls? I understand I can build a custom control from scratch, handling the clicks and painting myself -- though I'd prefer to stick with the native controls if possible.
Edit
I know it's a lot of buttons. My question is a technical one; not one about UI design.
WinForms doesn't handle displaying this many controls at the same time unfortunately.
If I were in your situation I would first consider if I could split up the form in several pages. In many cases that would be easier to understand for the user as well.
But in your case that doesn't seem to be an option. Are you making something like a minesweeper style game? There you have a grid of buttons that all are clickable. In such a situation I would suggest you go for a custom owner drawn control where you consolidate all the buttons in one control. Don't build a composite control that contains 225 buttons - that won't help at all :-)
A final option could be to switch to WPF. WPF uses hardware accelerated rendering so it may be faster, but with so many controls not even that may help.