ParallaxView Effect demonstrates how to use the ParallaxView Control which is part of the Fluent Design System in Windows 10.
Step 1
If not already, follow Setup and Start on how to Install and get Started with Visual Studio 2017 or in Windows 10 choose Start, and then from the Start Menu find and select Visual Studio 2017.
Step 2
Once Visual Studio Community 2017 has started, from the Menu choose File, then New then Project…
Step 3
From New Project choose Visual C# from Installed, Templates then choose Blank App (Universal Windows) and then type in a Name and select a Location and then select Ok to create the Project
Step 4
Then in New Universal Windows Project you need to select the Target Version this should be at least the Windows 10, version 1803 (10.0; Build 17134) which is the April 2018 Update and the Minimum Version to be the same.
The Target Version will control what features your application can use in Windows 10 so by picking the most recent version you’ll be able to take advantage of those features. To make sure you always have the most recent version, in Visual Studio 2017 select Tools Extensions and Updates… then and then see if there are any Updates
Step 5
In the Solution Explorer select MainPage.xaml
Step 6
From the Menu choose View and then Designer
Step 7
The Design View will be displayed along with the XAML View and in this between the Grid and /Grid elements, enter the following XAML:
<Grid Margin="50"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <AutoSuggestBox Grid.Row="0" Name="Value" QueryIcon="Add" QuerySubmitted="Value_QuerySubmitted"/> <Grid Grid.Row="1"> <ParallaxView Source="{x:Bind Display}" VerticalShift="100"> <StackPanel Spacing="5" Orientation="Vertical" HorizontalAlignment="Center"> <Rectangle Margin="10" Width="75" Height="75" Fill="Black"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Gray"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Red"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Orange"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Yellow"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Green"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Cyan"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Blue"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Magenta"/> <Rectangle Margin="10" Width="75" Height="75" Fill="Purple"/> </StackPanel> </ParallaxView> <ListView x:Name="Display"> <ListView.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Text}" VerticalAlignment="Center"/> <AppBarButton Grid.Column="1" Icon="Remove" Label="Remove" Tag="{Binding}" Click="Remove_Click"/> </Grid> </DataTemplate> </ListView.ItemTemplate> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> </Style> </ListView.ItemContainerStyle> </ListView> </Grid> </Grid>
The main block of XAML is a Grid Control with two Rows, the first Row contains a AutoSuggestBox and the second Row contains a ParallaxView which itself contains a StackPanel of Rectangle Controls and a ListView Control with a DataTemplate with a Grid of a TextBlock and a AppBarButton.
Step 8
From the Menu choose View and then Code
Step 9
Once in the Code View, below the end of public MainPage() { … } the following Code should be entered:
private class Item { public Guid Id { get; set; } = Guid.NewGuid(); public string Text { get; set; } = string.Empty; } private void Value_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) { Display.Items.Add(new Item { Text = Value.Text }); } private void Remove_Click(object sender, RoutedEventArgs e) { Item item = (Item)((AppBarButton)sender).Tag; Display.Items.Remove(item); }
There is a Item Class with a Guid Id and a string Text then the Value_QuerySubmitted responds when something has been entered in the AutoSuggestBox by adding an Item to the ListBox Control and Remove_Click will allow an Item to be removed from the ListBox.
Step 10
That completes the Universal Windows Platform Application so Save the Project then in Visual Studio select the Local Machine to run the Application
Step 11
Once the Application has started running you can use the AutoSuggestBox to add multiple items in the ListBox and when this is scrolled the Rectangle Controls will move in relation to the list to create a Parallax Effect.
Step 12
To Exit the Application select the Close button in the top right of the Application
This example shows how it’s possible to use the ParallaxView in an application which is part of the Fluent Design System to produce a Parallax Effect effect in a ListBox Control. It was when running this example once the April 2018 Update of Windows 10 was released that it was found the ParallaxView Control no longer functioned as it did in the Fall Creators Update – this was reported to Microsoft using the Feedback Hub for Windows Insiders where the problem was replicated and confirmed by the XAML Team, this allowed a fix to be created to allow the Control to function correctly once again – showing the value not only of this example but of a great relationship with Microsoft to allow something like this to be resolved.