This is the structure of my application:
Main Window has two ContentControls
Each ContentControl has a UserControl
Each UserControl has a ListBox
So graphically speaking, the user is presented with a Window with two ListBoxes: one with products and the other a shopping cart.
I want to enable drag-and-drop functionality among these two ListBoxes; i.e products can be dragged into the shopping cart.
I have seen examples of drag-and-drop between ListBoxes on the same window. But is it possible to drag and drop between UserControls?
I have looked at an example; is there a simpler way?
I came across a simple drag drop solution in Expression Blend; I tried searching for it, but in vain.
Drag-and-drop using behaviors is very simple. Download this complete implementation and sample and try it out:
ItemsControl Drag Drop Behavior for WPF
It is not clear what is a problem if you've already seen how to do drag-n-drop between listboxes on the same window. Use this code or tell us what's wrong with it.
The good thing about drag-n-drop functionality is that control which starts DND operation doesn't have to know anything regarding control which accepts DND result.
Related
I need a listview with multiple buttons for scrolling. E.g.
ScrollToTop Button
ScrollUp Button
ListView
ScrollDown Button
ScrollToBottom Button
I have got the buttons working in a WPF application by using the code mentioned here. Now, I need to reuse this by making it a control(lookless?). The layout of the listview and buttons can be horizontal or vertical. Should I use custom control or user control?
Here's what I'd recommend.
Don't use any pre-composed elements. Create a behavior ScrollList, accepting two parameters - Direction and Target, Direction will be Top || Bottom, Target you list - again you can use ElementName binding.
The reason why I'd recommend this approach is the actual code required to scroll your list is tiny, while managing layouts via properties in WPF is proved to be mess an anti pattern (yes you can go ControlTemplates, but it's definitely too havy for what you're trying to do).
If behaviors are too complex just consider creating a couple of commands.
I have a scenario where i have two different DataTemplates for a Listbox which i apply dynamically as needed while changing the ItemsSource of Listbox. The two DataTemplates containing different UI, all works fine i am able to swap between both Datatemplates.
My concern is the while swapping between the templates i want to add animation to give a feeling of change in UI, but right now it happens in one click its just applies other template at once which does not give a feeling of change in UI Transition.
So what i want to do whenever a different DataTemplate is applied to Listbox i want to apply transition animation which gives a feel of change in UI similar to what we do in Mobile application where when you select an item from Listbox it shows new list of items with a Transition effect.
I hope i am able to explain myself.
If anyone has done that short of work please help me how can i achieve the same transition effect while swapping two DataTemplates with each other.
Thank you
The Silverlight toolkit has a TransitioningContentControl that does exactly what you are after.
I think the WPF toolkit has one too, but cant find it right now.
You might consider converting the SL control to WPF - should be easy enough.
Or you could try this one from Codeproject instead
When performing dragging over TreeView I want items to expand automatically when mouse cursor is over them for some time (eg. 2 seconds). What would be the approach to solve this problem?
Ideally I'd like to have a custom attached behavior implementation of this problem, something like for scrolling while dragging: http://weblogs.asp.net/akjoshi/archive/2012/05/28/Attached-behavior-for-auto-scrolling-containers-while-doing-drag-amp-drop.aspx
In addition, I'd like to handle any other expandable (eg. Expander) or content-selectable (eg. TabControl) elements in a same manner, but I am not sure if all this can be handled generically (eg. with one attached behavior) or do I need to handle all of them separately?
See my blog article entitled Xaml: Adding Visibility Behaviors Using Blend to A DataGrid for WPF or Silverlight where it demonstrated a mouse over trigger. From that you can apply the behaviors you need using Blend to do the dirty work of adding the triggers.
I am trying to work though the best approach to accomplish the following. Within a page I have it divided into two section. On the left a listbox and the right is empty. (Grid etc). What I would like to accomplish is when an item is selected from the listbox a different user control loads in the right panel. For example if I have three items (one, two three) selecting one would load a red user control, two would load a blue user control and three a green user control.
I was taking this approach since Content Template / Data template selectors are not available in SL. However if anyone has another suggestion I would be grateful for your thoughts.
I'm creating this with MVVM in mind and traditionally I have managed this within the code behind of the user control however I have seen mention of how this could be managed within the ViewModel as well.
Any suggestions or guidance on a best approach is always appreciated.
Cheers
You can bind both listbox selected item and user control visibility properties to the same property in the viewModel.
Then just use a valueConverter for each user control to switch on/off the visibility.
Please tell me if i should elaborate/add a code sample.
i am trying to create a wpf app and have different parts in user controls.
in the navigation i have some buttons (now using the ribbon ctp). is it possible to change the main user control when different buttons are pressed in xaml. or is this just a bad way to do things?
sorry, really new to xaml and im trying to get my head arround it.
Further to what Carlo has said,
The way we do it is to have a blank grid in the place you want your controls to all appear and then use BlankGrid.Children.Clear() and BlankGrid.Children.Add() to set up which control is visible in this position.
We found that was the nicest programatically as we have a large number of custom controls, but Carlo's method would work nicely if you wanted to use the designer.
I think this is a pretty regular procedure in WPF. In my experience, me and other programmers put the controls where we want to show them and make their visibility hidden, collapsed or visible depending on what we want to show the user.