Animate removal of list items - xaml

I created an ItemsControl element in my XAML page. I added an animation when the new items are being added through the following style:
<Style TargetType="ItemsControl" x:Key="NotificationsList">
<Setter Property="ItemContainerTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition FromHorizontalOffset="-40" FromVerticalOffset="0" />
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>
This is great; the items slide in from the left as they get added.
Now, I need to add an animation for removal of items. I have two challenges:
How to apply an animation on an item when the object is removed from the bound ObservableCollection? For example, something like ExitingThemeTransition.
The items that get removed are always from the bottom of the ItemsControl. This causes the remaining items to just drop down by the height of the removed items, which seems to be difficult to follow. How do I make the animation that would gracefully move down the remaining items? Is that possible?
I am using Universal Windows Apps API (Windows 10 / WinRT). Thanks!

Related

Strange behaviour of combobox in WinRT

Comboboxes in WinRT have a default ItemsPanel of type CarouselPanel. This gives Windows 8.1 apps an "infinite loop" when scrolling combobox items.
If you don't want this behaviour, there are a lot of blog posts explaining how to "fix it".
For example this: Cancel WinRT ComboBox infinte scroll effect
or: http://netitude.bc3tech.net/2013/04/12/windows-8s-combobox-and-the-carouselpanel/
The problem with this solution is that you get a weird behaviour on the first item in the combobox.
How to reproduce:
Create a new blank Windows 8.1 app
In mainpage.xaml put:
<TimePicker Time="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
Create a style.xaml resource dictionary like this:
<Style TargetType="ComboBox">
<Style.Setters>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
Now start the app, select an item down the list (for example '05' minutes), then select the first item in the same dropdown (for example '00' minutes). The text in the dropdown control will now disappear.
Anyone know how to fix this? If I change the style of combobox itemspanel back to CarouselPanel it works (but with the infinite loop of course).
Just corrected this issue using a VirtualizingStackPanel in place of a StackPanel.
We had to set a size cause otherthise it take all the width of the screen.
<VirtualizingStackPanel HorizontalAlignment="Center" Width="150"/>
We didn't try to get a more flexible solution because we don't need it yet
Hope it will help you
StackPanel just not working with ComoboBox the possible solution is changing it to VirtualizingStackPanel, but you must bind with to the parent, otherthise it will stretch to screen width.
<ComboBox Name="ReasonComboBox"">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Width="{Binding ActualWidth, ElementName=ReasonComboBox}"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>

How to create a Doughnut chart in windows 8 app?

I am using the excellent Modern UI Charts for creating a Doughnut chart in my Windows 8 application. But I haven't been able to customize it much which has led me to look for other ways to create a doughnut chart. I would be very happy if anyone could answer my below questions on how to customize the Modern UI chart or if not then please do suggest on how i can implement my own Doughnut chart or any other FREE library which i can use to implement it.
Customizability questions on Modern UI charts:
How to increase the size of the Doughnut chart ? (Major Issue)
How to show percentages instead of numbers on the chart ? I know I can calculate the percentages and pass them to the chart but I will still not see the "%" symbol on the UI which will confuse the user as to whether the numbers are actual statistic number of percentages (Minor Issue)
Is there any way I can show the legend items vertically rather than horizantally ? (Minor Issue)
I would be happy if atleast I can increase the size of the chart otherwise I will have to look at a totally new way to create doughnut charts. Any lead or help on creating doughnut charts will be deeply appreciated. Thank you
1) You should be able to set the size of the chart. Try changing the chart style. If it's a larger PlottedArea that you want, the styles for those are in there as well.
2) You should be able to change the style for the PiePieceLabel. You can either set one for a given control or all over. Below is an example for setting it globally.
<Style TargetType="charts:PiePieceLabel">
<Setter Property="Background" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charts:PiePieceLabel">
<Border>
<!-- Changed it to a StackPanel -->
<StackPanel Orientation="Horizontal">
<TextBlock Text="{TemplateBinding Value}" />
<!-- May need a margin -->
<TextBlock Text="%" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
3) Yes. Same deal. Find the Legend style. Change it to display vertically.

Change the default page color on a window 8 store application

When I create a new page on a windows 8 store application it has default color which I want to change. If I remove all elements on the page and change the background color it has no effect. I've set the back ground to pink in my example below. How can I make this color take effect? (I've also removed everything out of App.xaml)
<common:LayoutAwarePage
x:Name="pageRoot"
x:Class="DemoWindows8StoreApp.BasicPage3"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DemoWindows8StoreApp"
xmlns:common="using:DemoWindows8StoreApp.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="Pink"
mc:Ignorable="d">
It's best to follow the default templates in that rather than setting the Background of the Page, but of the root element (usually a Grid), I'm not 100% sure why a Background on that page doesn't work (I suspect the control template).
UPDATE 1
According to Control.Background
Each control might apply this property differently based on its visual
template. This property only affects a control whose template uses the
Background property as a parameter. On other controls, this property
has no effect. For more info about visual templates, see the Template
property.
So there might be possible that Page's template doesn't use Background property as a parameter.
Remove nothing from the project to change the color. Go to Common\StandardStyles.xaml. Search for "LayoutRootStyle". You will find style for Panel. Change Background there. Please note this will be affected to all the pages in the project. If you want different color for different page then you can create separate style for each page.
<Style x:Key="LayoutRootStyle" TargetType="Panel">
<Setter Property="Background" Value="Pink"/>
<Setter Property="ChildrenTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>

Disabling Canvas entrance transtion

Nevermind. The issue was that I needed to disable transitions for the contained object which happened to be a Listview. had to disable the ItemContainerTransitions collection.
I dynamically add and remove elements from a Canvas element. When I do, the elements do that nice automatic animation which is completely unneeded for me (since I do all my own animation in this case).
I tried putting an empty TransitionCollection in the Canvas element in XAML and it does not seem to have any effect. I also tried adding an EntranceTransition with a zero offset, but that did not help either.
How do I tell Canvas not to animate my elements as they are added?
Here's what I tried:
<Canvas.Transitions>
<TransitionCollection>
<AddDeleteThemeTransition/>
<EntranceThemeTransition FromHorizontalOffset="0"/>
</TransitionCollection>
</Canvas.Transitions>
and
<Canvas.Transitions>
<TransitionCollection>
</TransitionCollection>
</Canvas.Transitions>

How to synchronize two scroll viewers

I have a custom WPF control to display a list of items using an ItemsControl. The ItemsPresenter is defined in the template to display the list and it is embedded inside a ScrollViewer for scrolling purposes:
<ControlTemplate TargetType="ItemsControl">
<Grid x:Name="LayoutRoot">
<ScrollViewer Margin="3">
<ItemsPresenter/>
</ScrollViewer>
</Grid>
</ControlTemplate>
My application creates two instances of the custom control to show the list side by side.
What I want is when user selects an item on the first one, the second control automatically scrolls so that the same item is displayed in the same position relative to the top. To accomplish this I need to know
How to get the position (in pixels) of the selected item in the first control?
How to scroll to the same position in the second control?
Are there any other ways to do this?