Lets say, I've a ListBox with hundreds of ListBoxItems. On the right side of the ListBox, there is a ScrollViewer which allows the user to see the items above or underneath in the current view of the ListBox. My goal is now to determine which elements i.e. ListBoxItems are currently visible. Is there a method to determine if a ListBoxItem is visible on the screen?
You can use ListBox.ScrollIntoView() to ensure a ListBoxItem is visible.
Can you use this rather than checking if it is visible?
You may use ListView instead of ListBox, since ListBoxItem's have a property called Bounds, which allow you to see the client coordinates of each item by returning a Rectangle object. Afterwards, you can compare these coordinates to the ListView's visible client area to determine if an item is visible or not. The visible area in a listview would be from x=0 to x=Width and from y=0 to y=Height. You can quickly test for visibility by using Rectangle.IntersectsWith(Rectangle)...
Related
I've got a Treeview with a number of items in it. Each item is the part name of a 3D object displayed in another control. I want to be able to move my mouse over the items and identify the item that I am over. This is so I can then pass the item id to the other control where I can highlight the part.
Note that I can already do this with the click event, but I need to do it without any clicking now.
How do I do this in the Mousemove event of the TreeView?
You have the class "System.Windows.Input.Mouse" that could provide you some information like DirectlyOver
But it could return you the top level of the UIElement so the TreeviewItSelf.
I thinks that another solution might be to test recursively the mouse position relatively to the item.
using Mouse.GetPosition(UIELEMENT) if the position return is negative in one of the coordinate or upper thant the control size that means your are not in the HitTestRectangle of the control.
You could also use VisualTreeHelper.FindElementsInHostCoordinates using a rect of size 1 at the relative position about you treeview (Mouse.GetPosition(TREEVIEW)) and you give in second parameter all the treeview itself.
Greetings,
I need to be able to drag and drop items that's contained in a Border.
So far I managed to find the border on the MouseLeftButtonDown event.
Now I wish for the item to move with the mouse when I have my mousebutton down.
I assume this can be done by simple settinga bool "dragging" to true when the item is clicked and then handle the moving in the MouseMove event.
But I can't seem to figure out how to move the item. Border doesn't have a property as Position or Location. Is there any way I can achieve what I want?
Perhaps there are controls for it that I dont know of?
Bit more background information:
I'm showing multiple columns (each column is a new canvas) with rows in it. Each row and canvas represent a cell. In a some cells I have a border containing a textblock with information. Upon clicking this border I wish for it to be bound to my mouse and move where I move my mouse.
I would recommend you use the Silverlight Toolkit which contains a framework for doing this sort of drag and drop work. Once installed open the documentation and lookup the PanelDragDropTarget control.
I'm displaying a number of controls (all the same custom type) that can change their height in response to user input. The controls are being placed on a panel that's configured to automatically create a scrollbar if needed. The controls are arranged as a single column list.
What's the best way to reposition them when something changes in height? Can I set something in the designer to do this automatically, or will I have to manually move all controls below the one that's size changes manually?
I suspect using a FlowLayoutPanel instead of a regular panel and refreshing after the child control changes height should do the trick.
I am trying to add vertical and horizontal scrollbars to my UserControl with the HorizontalScroll and VerticalScroll properties, but I am having extreme issues. My problem arises when I drag or manipulate the scroll box on the bar. When I let it go, it simply jumps back to the start position!
I know of the AutoScroll property, but I do not want to use it since I want to be able to control every aspect of my scrollbars, and I don't want it to be done automatically. Also, according to the documentation, AutoScroll is for "[enabling] the user to scroll to any controls placed outside of its visible boundaries" which isn't what I want. I just want scrollbars.
...aaand I suppose I could add VScrollBar and HScrollBar to the control, but why should I do this when the scroll functionality already exists? Seems like a waste to me.
Set the AutoScrollMinSize property.
If you implemented the OnPaint() override then you'll need to use the AutoScrollPosition property to set the arguments for e.Graphics.TranslateTransform().
I have this:
Each list is its own WrapPanel and they are all on another WrapPanel which is in a ScrollViewer. If I don't set the height myself for the main WrapPanel it assumes I want the WrapPanel as high as it can go giving me only one column whereas I want as many columns as needed to fill the window.
If I set the Width and Height of the WrapPanel that holds everything to fixed numbers, but I want it to change when the user resizes the window.
In your example screen shot and description I see a tab control whose anchor is set to Top, Left, Bottom, and Right. The tab page with AutoScroll set to true. Within the tab page I see a FlowLayoutPanel. The FlowLayoutPanel has its AutoSize property set to true. I also see a set of other panels/user controls each of which contains a title and a series of check boxes.
You can`t achieve this with standard controls. You can try to create your own custom WrapPanel implementation. But, actually, looking at original WrapPanel sources I think this will be quite tricky. You see, what you want, is basically to measure how many columns can fit in the current window, while every element in column can be of any size. The way I see that algorithm, it will require N*N iterations to get the final result. So you may have problems with performance.