- Part 8, 2 Developer Tools
- Part 9, DockPanel Control
- Part 10, OrbitView Control
- Part 11, PullToRefreshListView Control
- Part 12, Working with Headings
I created a Page with a Grid containing a ListBox and a Loading control. The ListBox gets loaded with a list of animals during load and the Loading control has its IsLoading property set to true. This is the property you would normally toggle on and off while a long-running load process is occurring. Here's a look at the XAML:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <ListBox x:Name="MainItemsList"/> <controls:Loading x:Name="MainLoadingControl" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Background="DarkGray" Opacity="0.8"> <StackPanel Orientation="Horizontal" Padding="8"> <ProgressRing IsActive="True" Margin="0,0,10,0" Foreground="CadetBlue" /> <TextBlock Text="Loading control with wait ring. Loading..." VerticalAlignment="Center" Foreground="White"/> </StackPanel> </controls:Loading> </Grid>
Inside the Loading control, you can set any content you want to display for your users during the wait interval. I've chosen a horizontal StackPanel with a ProgressRing and TextBlock. Of course, a production app would probably move the content of this panel into a shared resource that could dynamically set the text of the TextBlock based on the current context of the wait/load period.
This is the code from the Page's code behind file to load the list items and display the loading panel.
private void MainPage_Loaded(object sender, RoutedEventArgs e) { var listItems = new List<string> { "Item 1 - Dog", "Item 2 - Hamster", "Item 3 - Rat", "Item 4 - Cat", "Item 5 - Lizard", "Item 6 - Guinea Pig", "Item 7 - Snake", "Item 8 - Turtle", "Item 9 - Bird", "Item 10 - Gerbil", "Item 11 - Mouse", "Item 12 - Fish" };
MainItemsList.ItemsSource = listItems; MainLoadingControl.IsLoading = true; }
Again, best practices outside of a sample app would have these list items inside an ObservableCollection in the corresponding view model. The IsLoading property would also be bound to a boolean in your view model to be toggled on/off as necessary.
This is the end result of our basic list behind a Loading control.
It looks pretty slick for a few lines of code in a sample app. Go download the latest Toolkit in your UWP app and give it a try today. The GitHub source for the control can be found here.
Happy coding!
Technorati Tags: uwp,uwp community toolkit
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.