I have a DataRepeater with some shapes on the ItemTemplate that I want to toggle on and off based on data in each Item. With every other control, I have done similar things using e.DataRepeaterItem.Controls["whatever"] in the DrawItem event, however this doesn't work with a shape as shapes are held in a ShapeContainer within the ItemTemplate. Trying to access the shape using ShapeContainer.Shapes.get_item(int index) results in a null reference error. As best as I can figure, the shapes in the container have not been initialized at the time of the DrawItem event.
So, what is the best way to modify a shape in an Item if I can't do it when each Item is drawn?
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.
I have a WapPanel in my Xaml code.
What kind of items exactly i can add into it?
I know that I can add some Shapes to draw, but I want add and show some Lable or TextBlock with those shapes. How can I do this?
Wrappanel uses UIElementCollection for its children so you can add any UIElement
So basically you can add any
Control (TextBox, Label etc), Shapes, Lines, pretty much anything except Windows
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 need to create a form with two panels:
1. Destination
2. Source
On the source panel there will be picture boxes. I need to be able to move it from source to point at destination panel with mouse.
I have a problem connected with different coordinates of the panels.
Please, help with advice or an idea what to do.
Moving those controls requires changing their Parent property. That's not easy to do, there is no good time to do this while the user is dragging with the mouse. You'll also get the effect of the panel clipping the control, you cannot display it on both with half of the control on one and the other half on the other panel. And yes, you have to change the Location property of the control when you change the parent or it will jump.
Punt the problem, don't use two panels. It only has to look like a panel, easily done by drawing one in the form's Paint method (or OnPaint override, better). Use e.Graphics.DrawRectangle or FillRectangle.
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)...