I've noticed a strange bug when creating a desing with xaml:
sometimes I'm able to "select" controls the way I'd select text.
Normally the controls would look like this:
while if accidental selection happens, it looks like this:
Why does this happen, and how do I prevent it?
UPDATE
Here's the controls that I'm using:
TreeView->Expander->StackPanel->DataGrid
Based on the answers, the problem probably originates from TreeView.
How do I prevent TreeView items from being selected?
It appears your control is based off a listbox which supports being able to select items in that manner. Perhaps change the underlying control to be based on an 'items control' instead.
Edit:
Tree view has the same behavior allowing to select an item. See this question...
Disable WPF TreeView (or TreeViewItem) selection?
That should only be the case if the control is inside something selectable like a ListBoxItem, to prevent that use ItemsControls instead of subclasses of Selector (e.g. ListBox). If that is not it i don't know what is going on as i have never seen something like that.
Judging from your edit you appear to have TreeViewItems, you could either override the respective brush-keys to hide the selection or add a TreeView.ItemContainerStyle which changes the Template to something which will not show the selection in the first place.
Related
I'm pretty new to c#, the first thing that I'm trying to make is a ListView with data bindings which has turned out ok.
I'm now trying to make items have a twist button if the underlying model has any children (like the TreeView). Each of the children will have columns the same as all the top level items.
How would I go about doing this? Is there an already existing control like this? If not would I be better off dressing up a TreeView to look like a ListView, or dress up a ListView to look like a TreeView?
I went down the road outlined in this solution which dresses up a TreeView, but the end result looks pretty awful and the heading is actually just an item, so you lose all the nice column sizing and column buttons that can hook up to column sorting that you get in ListView so that route actually seems like it would be more work.
I noticed the new task manager has a control exactly like what I'm trying to create, I don't know how this made? probably in C though.
Microsoft provides a sample that appears to be what you are looking for. A write-up of the example can be found here:
http://msdn.microsoft.com/en-us/library/vstudio/ms771523(v=vs.90).aspx
When you build and run the example you will end up with something resembling this:
There is a large amount of templating done in the example, so you will be able to make things look the way you want.
What you describe sounds a bit like a TreeListView, and if you google 'WPF TreeListView' you will see some solutions that might be good for you. I have used one from Telerik, but it might be overkill depending on how complicated your needs are.
If you only want one sub-level like the image you attached, you might want to just roll your own using a ListView with a complex DataTemplate for the first column which would show an expander button and a simple ListBox bound to the children items.
Similar to the answer here, except your cell would have a checkbox styled to look like the arrow, the text for the item, and a child ListBox. Then bind the visibility of the child ListBox to the state of the checkbox.
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.
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.
I have a custom control and I would like it to act like a button i.e. when you hover over it changes a little so it seems "clickable" to the user
I actually acheived this using the MouseEnter and MouseLeave events and changing the gradient but...
is there a way to apply a style to the user control and say something like TargetType="button" so that it "acts" like a button automatically?
I feel the way i'm doing it is not the best way
As sniper says, you can set a Controltemplate for each state.
Alternatively, you can completely replace a control's visual tree with anything you want - while still keeping the control behavior intact. Check out this post by ScottGu on the topic
In Expression Blend 3, you can edit the different states (Normal, Hover, pressed, selected etc), of any control how you need it. just select your control and click Edit copy template
Add border object and sets its visibility on mousehover and leave event on the control (This will look like a flat\popup button). Additionally set the control's cursor to hand.
You can derive your control from ButtonBase, just like Button, HyperlinkButton, Checkbox, etc.
Visual Studio QuickWatch window has a hierarchical property grid control. Is a control like that available somewhere?
The default property grid control doesn't seem to work for me as it requires the objects to have an ExpandableConverter attribute to work the way I want. Although, if any of you know a way to turn the property grid into a QuickWatch-like control it would also be accepted.
Thanks.
It is very spread type of control. Each Library-of-Controls company created at least one.
http://images.google.com.ua/images?q=tree%20like%20grid
Here you have two samples:
http://www.codeproject.com/KB/grid/PropertyGridExWinForms.aspx
http://www.howtocode.net/software-development/c/propertygrid-utilities
I don't think so, its something you would have to create your self.
looks like it wouldn't be to difficult, I think its DataGridView where the first column is a custom cell that when clicked does a hit test to see if its hit a node glyph.
But i could be wrong.