I have a WPF ListBox control which displays items of an RSS feed. I occasionally check the source of the RSS feed for new items. Once I detect a new item I add it to the observable collection which immediately adds the new item to the ListBox display.
Is there a way to 'slide in' the new item from the top, pushing down the existing items? How would I achieve such an effect? Can it be done with a ListBox, or do I need to resort to my own container, such as a StackPanel and animate for example the Height of newly added controls programmatically?
I just posted an answer to this question which is very similar to yours.
WPF how to animate a list of components
It can be done with a ListBox. Use the ItemContainerStyle to style the ListBoxItems that the binding creates for you: this style can include animations, e.g. by adding an EventTrigger for the Loaded event to the Style.Triggers, and transforms. For example, in your trigger action you could animate the Height so the item expands into place, or if the height is unknown you could have your style set a ScaleTransform and in your trigger action animate the ScaleY of that transform from 0 to 1.
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 using the MahApps Panorama Control in my project by linking the Mahapps.Metro.dll so I can't change the XAML-Code of the Panorama Control directly.
I thought it would be possible to override values in my MainWindow.xaml but when I do so nothing changes or maybe I change the wrong property.
The problem with the Panorama Control is that the selected item has a white border and I can't find a way to remove this selection style. I tried several solutions like changing the style or changing the control template (How to disable highlighting on listbox but keep selection?) but my changes have no influence of the Panorama Control.
There you can see the Panorama Control XAML.
This is an issue with the way that the Styles are inherited, and it's tricky to see how the ListViewItems and ListBoxItems work together. I fixed this by inserting the following in the code behind. It does, however, lose your selected item:
var listbox = MyPanorama.FindChildByType<ListBox>();
if (listbox != null)
{
listbox.SelectedIndex = -1;
}
FindChildByType is a simple search to return the first ListBox that is found under the Panorama. If you have a search by name the x:Name of the template listbox is "items".
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.
I have a MiniToolbar popup that shows up at Mouseover on a ListBoxItem, it needs to show just under the item.
(a MouseOver trigger also sets the IsSelected property on the items)
I tried two options :
define the popup on the items DataTemplate
define the popup on the ControlTemplate for the ListBoxItem
Both options work fine, however I was wondering if the popup was recreated each time ??
(please advise)
I think it would be better to define the popup in the ControlTemplate of the containing ListBox rather than the ListBoxItem ?
I tried this, but could not find the binding expression for placement property relative to the SelectedItem (it shows up at the bottom of the ListBox, not bottom of ListBoxItem).
Any suggestions ?
thanks in advance.
Michael.
The popup is created one time for each list box item in both cases.
I would not suggest that you use single popup for all items in the CotnrolTemplate for the list box because it significantly complicates things. But if you still want to do so, you can set Placement="Custom" on you popup and specify CustomPopupPlacementCallback. In that callback you can calculate the placement using the position of currently selected item.
I'm using a DataTemplate that animates a RenderTransform to increase its size when the mouse is over it. The problem I'm having is that when the animation is in effect the enlarged list box item appears behind other items. Is there a way to control the ZIndex of the list box item from within my DataTemplate so that it's always on top of other items?
You can set the Templated Element's ZIndex from template using Triggers. Find out the templated parent control by VisualTree parsing like bellow
{RelativeSource FindAncestor,AncestorType=...
The zIndex is only available on elements hosted inside a Canvas. Therefore you may be able to wrap the whole listbox control in a canvas then set Canvas.zIndex to 99 as part of the Trigger you are using to do the transform . However I could not get this to work.
The only other option that did work is to use a LayoutTransform rather than a RenderTransform as this will move the other items out of the way as the transform is calculated before the items are placed. This would mean there would be no need to set any zIndex, however it would depend on your requirements.