WPF fail

Aug. 10th, 2009 11:02 am
paperclippy: (grr)
According to Reflector, ComboBox has the following code in it:

private static void OnMouseButtonDown(object sender, MouseButtonEventArgs e)
    ComboBox box = (ComboBox) sender;
    if (!box.IsContextMenuOpen && !box.IsKeyboardFocusWithin)
    e.Handled = true;
    if ((Mouse.Captured == box) && (e.OriginalSource == box))

What does this mean? It means that even if you derive your own ComboBox, you will never receive any MouseDown events. Ever. Unless you hook up a handler to view Handled events.

The result is that if you have a combo box inside a ListBoxItem using a DataTemplate, clicking on the combo box will not select the item in the list, whereas clicking anywhere else in the row will select the item. This is incredibly stupid, and is the cause of a bug for me, since my context menu for the ListBoxItem operates off of the selected items in the list, and you can get into a situation where you open a context menu by right-clicking on the combo box while nothing is selected, and the context menu doesn't know what to display.

WPF, why did you do something so ridiculous? This is kind of like how you have to derive your own ListBox if you want multiselect drag/drop to work. How did this not occur to them?
paperclippy: (grr)
Why do you not respect minimum and maximum sizes? WHY??? I am left doing all sorts of crap because I want my control to size to its content, but if it hits its maximum size, I want the content to size to IT. Plus, its maximum size is dependent on the current sizes of OTHER things. Argh.

Because WPF fails to work as I expect, I have spent the past two days trying to implement a feature that would have been super-easy with SplitPanel in WinForms.
paperclippy: (Default)
For anyone who was wondering, here is how I solved the problem. First, any time the window is resized I set the base grid's width and height equal to the client width and height, which I get by using interop to do my Win32 call to GetClientRect. Then I set the window's minimum width and height equal to the sum of the minimum widths/heights of my grid contents plus the difference between the values I get from GetWindowRect and GetClientRect.

When I drag a gridsplitter, I handle the DragDelta event. When I get a DragDelta, I set the MaximumSize of the pixel-sized grid piece (ColumnDefinition or RowDefinition) I'm dragging equal to the total grid size minus the min sizes of the other pixel-sized rows/cols minus the actual size of the star-sized rows/cols. I also set those maximum sizes when the whole window/grid is resized.

Additionally, when the window is resized I compare each DefinitionBase's actual size to its maximum size, and if it's bigger I set it equal to the maximum size with pixel sizing.

There are also min sizes set on all my DefinitionBases. If anyone is interested let me know and I can explain better or send you a code snippet.
paperclippy: (grr)
Maybe some of the WPF users who read my LJ can help. If not, at least I get to rant.

Here are the problems:

  1. GridSplitter only really works right if everything is using star sizing.
  2. GridSplitter likes to ignore the minimum sizes you have set on columns.
  3. If you are using a GridSplitter between a pixel-sized column and a star-sized column, when you drag, rather than the GridSplitter stopping when it hits the star-sized column's MinWidth, it will keep going and resize the grid so it's bigger than your window such that you can push all of the star-sized column off the window entirely.
  4. The obvious solution would be to bind your Grid's width and height to the Window's width and height (since of course having its HorizontalAlignment and VerticalAlignment set to Stretch doesn't fix this problem). But wait! What about the window frame? Okay, you say, I will bind the Grid's width and height to the Window's client width and height. Sounds easy enough. EXCEPT THERE IS NO EASY WAY TO GET THE WINDOW'S CLIENT AREA. This was incredibly simple to do in WinForms, but nearly impossible in WPF. In fact, the solution I have seen proposed is to actually do a pinvoke of the Win32 function for GetClientRect.
  5. Windows do not respect the minimum sizes of their content. For example, if I have a Window and in it I have a Grid, and my Grid has MinWidth and MinHeight set, I can still resize my Window down to nothing. Note that attempting to bind the Window's MinWidth and MinHeight to the Grid's encounters issues because of the window frame too.

Gaaaaaah. Apparently the "correct" solution to at least the GridSplitter problems is to create a custom GridSplitter that will magically work right. Too bad nobody posted their code online, and I am left flailing trying to figure out what I need to do in my GridSplitter to make it work!
paperclippy: (grr)
I can't believe that I have to wait for SP1 to be released in order for multiselection and drag/drop in a list box to work right. That is so incredibly stupid. Who tested this stuff? What made them think that if I select a bunch of items and want to drag the whole group, I have to hold down the control key while selecting the last item and instead of clicking on it start the drag then?

The worst part is that all the fixes to this that I've found online result in breaking another part of my app. Arrrrrrrrrrrgh. Apparently it will be fixed in SP1, which is out in beta right now, but I need to wait for an official version.
paperclippy: (afroken)
How did I get around the issue where I wanted to put a trigger in my DataTemplate that triggered off of the number of times a particular value appeared in my collection? MultiBinding passing both the particular item and the entire collection to a converter which returns a color. Booyah. I drink your milkshake, WPF! I drink it up!
paperclippy: (huh?)
I don't know how many of you guys are WPF gurus but I know at least [livejournal.com profile] sithjawa knows WPF, so here goes.

We have several cases where we need to drag and drop between WPF controls and WinForms controls. As far as we can tell, this only works if the drag data is a string. So as a workaround we have this wacky static hash table where every time we want to drag something, we get a new hash key to use as the drag data and stuff it in the table.

What is the *correct* way to do drag & drop between WPF and WinForms (and vice versa)? Or does it just not work?


paperclippy: (Default)

April 2017

161718 19202122


RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 21st, 2017 12:14 pm
Powered by Dreamwidth Studios