ListBox with pop-out/popup item details - c#

I would like to create a listbox, with a details pop-up/tooltip kind of window.
Scenario is as following:
List of items
Show details of selected item
Details should be displayed outside the listbox and overlaying any controls that happens to be nearby.
The problem about using tooltips is that they disappear after a while. And the problem about using pop-ups is that they do not move, when the window moves (?)
So I'm just looking for some pointers on how to solve this.

Use ToolTip object. It has autopositioning and nice graphical style out of the box.
Simply use it like this:
toolTip.PlacementTarget = yourSelectedItem;
toolTip.Placement = PlacementMode.Right;
toolTip.Content = {place whatever you need to display here};
You can control its visibility with the IsOpen property.

Adorners were built for things like these.
That said, if I were doing this I would set "StaysOpen" on a Popup to false. So when the user clicks somewhere else it will automatically disappear (ie when window is moved). Do you really see your users moving the window so often while looking at the details? Going down the adorners route is not all that easy. It has its own complications.

Related

"Correct" Way to Show New Controls in WPF

I'm designing a small helper utility with a simple UI. I'm working off the following mockup:
The execution flow is meant to be as follows:
User clicks "Other" radio button.
A textbox is presented and user is prompted to write in a response.
My question is: What is the "correct" way to achieve the UI change from the picture on the left to the picture on the right? My options seem to be either create a unique window for each, or have all of the controls on the same window and just play with the visibility of the controls.
There is no "correct" way really. It all depends on your requirements.
If you want the new screen to show up in a new window, then create a new window. If you want it to show up in the same window and simply replace the previous screen with the radiobuttons, then toggle the Visibility property of the individual controls or the parent Panel, preferably using a view model that has either bool or Visibility source properties that you have bound to in your view.

In a property grid is there a way to unselect all grid elements programatically?

I am working on a project in which I am using a property grid to display the properties of the selected control.
The Property Grid is fixed to the left edge of the container and in the rest of the space I have the form I am designing.
On clicking a control on the form, the specific control’s property is getting selected.
In the above figure, I have selected the textbox and the textbox’s properties get shown on the propertygrid.
Here if you observe, by default, the Name property is highlighted as well.
Is there some way to unselect this property programmatically?
I have tried some suggestions online but none have helped. I am not able to find find a way to remove all selections from the PropertyGrid, but its behaviour seem to be different form a DataGrid...
Here is why I need this...
On selecting a control, if a property in the property grid is selected, then the property is getting modified.
For example, If i cut the control using Ctrl + X, the selected value in property grid is getting cut which in some cases is forcing user to set the property before modifying anything on the form.
I have tried selecting multiple controls, but in that case alse the selected property seems to be persistent
Since PropertyGrid uses DefaultProperty to select a property in its grid, as an option you can set DefaultProperty attribute at run-time for your object to a non-browsable property, for example:
this.propertyGrid1.SelectedObject = null;
TypeDescriptor.AddAttributes(someControl,
new Attribute[] { new DefaultPropertyAttribute("Site") });
this.propertyGrid1.SelectedObject = someControl;
Well, what you are trying are hacks. It is never a good idea to do such hacks particularly if you are not the only person that use the software.
In your case, the focus should be on the designer while you interact with it. So if the user press Ctrl+X, the designer should respond to the keyboard and it should not have any effect on the property grid (as only one control can have the focus at the same time).
Thus it is up to you to make sure that your designer is focusable, that it has the focus when initially displayed, that it get the focus when you press the TAB key. Pressing the TAB key again should put the focus on the property grid so that user can interact with the grid without using the keyboard.
If you have more than these 2 controls, then obviously TAB should also stop at any appropriate controls. Also, it can be a good idea to have some direct shortcuts like F4 to (show and) activate the properties pane.
If you are not able to make it works, then the best compromise would be to use another windows for the properties grid. By using a distinct Tool windows for the properties, it should not respond to the keyboard when the main windows has the focus.
Here are some links that might help you:
Panel not getting focus
Control.Focus Method() — See Remarks section.
In any case, you should not prevent Ctrl+X to works as expected when the property grid has the focus and a property is selected. Users don't like software that do not follows UI conventions.
As a software developer, you should as much as possible ensure that your application follows standard behaviors. I recommend you that you take one or 2 extra days developing your software properly instead of doing hacks.
Often, compromise to gain a few days will never be fix and will be a pain for many years. Better to do it right from the start. Unselecting an item in the property grid is not an acceptable workaround. Your manager should not allows you to do that.

How can I make a button which pops up and also hides a window in WPF?

I am fairly new to WPF and I need a little help on this one.
I have an application where I have an accountmanager, which enables the user to see all their accounts (by email) in a ListBox.
Is there a way I can add a button which can pop up a window,
on every listbox item (which holds an account each)?
The button should also be able to hide the window.
EDIT:
I have another way to make the window show, not by button, but by right-click instead. I was just wondering if someone had a quick answer.
Thanks in advance!
You could have a StackPanel as your listbox item and have it contain a Label for the account email string, and a Button that shows whatever window you want to show. You can set the StackPanel's orientation to fit your needs as well.

Custom wpf tab control with one permanent tab, all other tabs scrollable

I need to create a control which has a single permanent tab ("home"), and all of the other tabs are scrollable.
Right now I am trying to achieve this result by subclassing the TabControl, adding an extra button (which looks like a tab) to the overridden template, and setting the SelectedIndex to -1 whenever the button is clicked. When SelectedIndex is -1, a trigger causes the TabControl's ContentControl to be bound to a special "Home" tab's content. Basically, I am faking the behavior of a real tab and overriding the ability to deselect all tabs in doing so.
This seems to work, except for two problems:
Select example tab #3, then select home. THEN, try to select tab #3 again. Tab #3 doesn't respond.
Select tab #3, then select home. THEN, try to use the menu which happens to be in the same window. When I go to use the menu, #3 pops up as the selected tab again.
I've tried to listen to all kinds of events associated with the TabControl at this point, but none of them seem to give me something I can work with to get around these behaviors.
Is there something out there that will allow me to override the default SelectedIndex behavior? Should I be doing this another way? Ideally, I would like some way to take in a collection of tabs that allows me split up the tabs visually without losing the basic functionality of a TabControl.
The only way I can think of to accomplish this would be to use a custom ControlTemplate for the tab control. You can use StyleSnooper to get the current template. The that is part of that template would need to be replaced with a custom panel that you wrote. You base that on Panel. You would only need to override ArrangeOverride so that it arranged the Home tab in its place, and the others depending on the scroll position.
I was able to implement this by writing my own custom tab panel, as AresAvatar suggested. However, the panel needed to extend from the ConceptualPanel implementation from http://www.codeproject.com/KB/WPF/ConceptualChildren.aspx. The problem is that the panel needs to have IsItemsHost="true" in the TabControl template to preserve the tabs' selection behavior. Unfortunately, once a normal panel is an items host, it's Children can't be changed from inside it's own class code. So, I couldn't add the scroll buttons that I needed. I was able to get around that problem with the ConceptualPanel by adding everything (tabs + scroll buttons) via AddVisualChild.
There might be a better way to do this, but this worked for me.

DataGridView cannot be Focused, but one of them can

I've come across the strangest bug pertaining to DataGridViews in Windows Forms.
I have a TabControl, that is supposed to contain a docked DataGridView in each tab page. I thought it would be convenient that the grid is focused upon changing the tab page, so that the user could simply hover the mouse over the grid and start scrolling when he changes the page. So, I just put a grids[tabs.SelectedIndex].Focus() in the event handler for changing the tab page.
However, something really strange happened. In my test application, I have three tab pages. If I try scrolling the grid right after starting the application, it doesn't work; I have to click in the grid first. I was expecting this. However, if I change the tab page, I can't scroll in any of the other grids until I click, except for the first one!
So, if I switch pages to the second page, then back to the first, I can automatically scroll that grid without clicking, but if I then switch to the third, I have to click for the grid to focus.
I had a look at the CanFocus properties of the grids, and it seems that only the first grid has it set to True. They are all created programmatically, and all in the same way. I don't see why they would be different.
Any ideas?
Inactive tab pages have their Visible property set to false. The documentation for CanFocus says:
In order for a control to receive
input focus, the control must have a
handle assigned to it, and the Visible
and Enabled properties must both be
set to true for both the control and
all its parent controls
Well, I solved it. Stupid programming error on my part, I had grids[tabs.TabIndex].Focus() instead of grids[tabs.SelectedIndex].Focus().
Oh well.

Categories

Resources