I implemented a drag and drop of an image from a Grid to another Grid using built-in MouseDragElementBehavior class. Then I needed to use a bit more complex layout for the source items so used ListBox and ItemTemplate instead.
The problem is now when dragging an item from the ListBox it is only visible when above the ListBox. How do I make it always visible and following mouse cursor anywhere while being dragged?
I suggest that instead of writing your own implementation using the Blend SDK, that you use the Silverlight Toolkit ListBoxDragDropTarget control.
The reason the item disappears in your element is that the MouseDragElementBehaviour is simplistically applying a render transform to affect the movement. However the ListView places its item panel inside a ScrollViewer which clips its content to its viewport.
Related
That might be a silly question, but I just can figure how to resolve it for now.
I'm building a wpf application with drag and drop between a ListView and a Grid.
My items being consituted by an Image and a TextBlock. I have defined a DataTemplate with a StackPanel containing these controls and applied it to ListView items and ContentControls inside of the Grid cells.
Basic idea is to chose items from the ListView and drag them to a cell. So my grid is empty at the beginning.
My problem, besides of sucking at making my controls filling correctly my grid (bonus ninja question !), is that when no item is chosen in a cell the image is not drawn and will not act as drop target. Only the TextBlock will.
Is there a way to counter that ? Thank you :)
You can set a datatemplate trigger so that you display an empty image that will accept the drop, if the contents are null.
And if that idea doesn't work, you can create a datatemplateselector that returns a template with a blank dropping target if the content is null. This shows how to make a selector that can let you set all possible templates using only xaml.
I am trying to make a panorama-like control in WPF c# that scrolls to/brings into view only one grid from a horizontal set of grids. I need to expose the command which allows me to scroll forward/backward from various controls (which using an InteractionTrigger would suffice) on any of the grids in the ScrollViewer or ListBox.
I want each of the internal grids to size to the actual height/width of the usercontrol they live in (like tiled pages), won't need any scrollbars, and will eventually be applying easing effects/states to each of the scroll positions.
If this is too vague/convoluted, please let me know.
Thanks in advance! :)
Easy Solution:
PathListBox. Downloaded the PathListBox toolkit (for the PathListBoxScrollBehavior), set the capacity to 1, and used the templated InteractionTriggers to bind various source objects on my grids to the InvokeCommandAction Increment/Decrement Commands. Then I added easing effects/GoToStateActions.
I realize this is sort of a cheat, but am still going to search for the "real" way to do this with custom control templates deriving from ListBox and/or ScrollViewer.
I am currently working on a WPF project in C# using MVVM. In this project I have a list box that loads a user control for each row of data in my items source.
The user control that gets added for each item in my collection also contains a list box that is filled from a database. This second list box often grows and therefore makes each item larger than the view of the first listbox.
My question is, how to I make my listbox have smooth scrolling. Right now it jumps from the top of one item the the top of the next. Since each item is bigger than the view of the listbox I need to be able to scroll without jumping from the top of each item to the next.
I have used a scrollview to achieve this but the list box then intercepts the mouse wheel event and will not allow me to scroll without hovering over the scroll bar.
Is there a better way to do this?
UPDATE:
I can get smooth scrolling using the scrollview control but I cannot scroll while my mouse is inside the scrollview. I have to have my mouse over the scrollbar in order to scroll.
It is like something is intercepting my mousewheel event.
I was able to achieve what I was trying to do by using a ItemsControl rather than the ListBox. It loaded just like the ListBox control and pulled all of my data into it and let the ScrollView handle the scrolling. It did not intercept the mousewheel even like the listbox did.
If you do not need to be able to select an item, I highly recommend using the ItemsControl.
You can set on the Listbox the following Property ScrollViewer.CanContentScroll="False".
I am working with a WPF application that uses alot of drag and drop. Everything is working fine, with exception of ListBoxItems. I have a ListBox with ListBoxItems that can be dragged to another target( a StackPanel). The problem is, when I drag the cursor outside the ListBox, I cant see the Adorner that I have setup with the ListBoxItem?
I know this is a common problem, but I am just not sure how to fix it. Is there something that I need to do to allow me to drag outside of the ListBox control?
Below I have attached what the UI looks like so far. As you can see, there is a ListBox on the bottom left. When I drag an item, the adorner appears, and follows the cursor around while the cursor is over the ListBox, but if I try to move the cursor away from the listbox, the Adorner seems to almost go under the other controls(zIndex?).
Edit - Solution
I have changed the code to handle the AdornerLayer relative to the window as oppose to relative to the AdornedElement
So I changed
layer = AdornerLayer.GetAdornerLayer(_originalElement);
to
layer = AdornerLayer.GetAdornerLayer(this);
This solved the problem of the ScrollViwer clipping the AdornerLayer
The ListBox (or, to be specific, the ScrollViewer within the listbox) clips any adorners attached to it's children. This is done to ensure that adorners for items scrolled out of view are not shown. To get around this, you need to explicitly put thing in the Window's adorner and not that of the listbox or listboxitem
I'd like to create a dropdown panel in WPF the acts like a ComboBox/Expander hybrid. I'm currently using an Expander but it pushes the the controls underneath it down when it expands.
I simply want it to act like a ComboBox and overlay it's dropdown. I've looked at using Popups but they don't move with the underlying window when it's moved.
So, I've concluded that the closest control to my needs is a ComboBox which allows me to put a Grid or StackPanel into its dropdown area.
Any ideas how to achieve this?
I am not exactly sure what you want to do:
But the layout depends very much on the parent control. If your controls are in a Stackpanel all controls will be moved if a control expands or changes its size. If you use a Canvas you can align controls on top of each other.
Also Adorner are useful when you want overlay something above something else.
You can change the appearance of the ComboxBox and you can put a grid or anything else inside it. Have a closer look at ItemTemplate.