Step 1: Make a grid having two rows and named grid "ImageSlideShow".
<Grid x:Name="ImageSlideShow"> <Grid.RowDefinitions > <RowDefinition Height="410*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions></Grid>Step 2: Make a Stackpanel in Grid row 0 and place an image in Stackpanel.
<StackPanel Grid.Row="0" > <Border BorderBrush="White" Grid.Row="0" BorderThickness="4"Width="700"> <Image x:Name="ImageSource" Source="uri"AutomationProperties.Name="ImageSource" VerticalAlignment="Top" Stretch="Fill"Height="380" Width="700"> </Image> </Border> </StackPanel>Step 3: Make a new Grid in main Grid row 1. Add a stackpanel in new Grid then add 4 buttons in stackpanel.
<Grid x:Name="Input" Margin="456,428,455,0" VerticalAlignment="Top"HorizontalAlignment="Center" Height="198"> <!--Add stack pannel and set its orientation horizontal--> <StackPanel Orientation="Horizontal" Grid.ColumnSpan="2"Margin="0,0,0,-45"> <!--Add 4 buttns to stack pannel--> <!--You can use style of app bar buttons or you can also use images--> <!--Generate click events of all these buttons--> <Button x:Name="playSlideshow" Margin="0,0,10,121"Click="playSlideshow_Click" Style="{StaticResource PlayAppBarButtonStyle}"Width="115"/> <Button x:Name="pauseSlideshow" Grid.Row="1" Margin="0,0,10,0" Click="pauseSlideshow_Click" Style="{StaticResource PauseAppBarButtonStyle}"/> <Button x:Name="previousItem" Grid.Row="1" Margin="0,0,10,0"Click="previousItem_Click" Style="{StaticResource PreviousAppBarButtonStyle}"/> <Button x:Name="nextItem" Grid.Row="1" Margin="0,0,10,0"Click="nextItem_Click" Style="{StaticResource NextAppBarButtonStyle}"/> </StackPanel> </Grid>Step 4: Open the MainPage.Xaml.cs from Solution Explorer.
Step 5: Add a Dispatcher Timer
public MainPage() { this.InitializeComponent(); } //Add Dispatcher Timer DispatcherTimer playlistTimer = null; //Rightclick to play to Manager and Resolve PlayToManager playToManager = null; //Rightclick to Coredispatcher and Resolve CoreDispatcher dispatcher = null; //Make a list of strings List<string> Images = new List<string>();Step 6: Add a method
protected override void OnNavigatedTo(NavigationEventArgs e) { //add imags thatyou want to show in your slide show Images.Add("a.jpg"); Images.Add("b.jpg"); Images.Add("c.jpg"); Images.Add("d.jpg"); Images.Add("e.jpg"); Images.Add("f.jpg"); Images.Add("g.jpg"); playlistTimer = new DispatcherTimer(); //Set the Time span in which the IMAGE is changed, like here i set interval of 3 sec playlistTimer.Interval = new TimeSpan(0, 0, 3); playlistTimer.Tick += playlistTimer_Tick; playToManager = PlayToManager.GetForCurrentView(); playToManager.SourceRequested += playToManager_SourceRequested; //right click to bitmapimage and reslove ImageSource.Source = new BitmapImage(new Uri("ms-appx:///Assets/" + Images[count])); }Step 7: Set the source and count in which image will rotate
private void playToManager_SourceRequested(PlayToManager sender, PlayToSourceRequestedEventArgs args) { var deferral = args.SourceRequest.GetDeferral(); var handler = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { args.SourceRequest.SetSource(ImageSource.PlayToSource); deferral.Complete(); }); } int count = 0;Step 8: Method of timer tick
private void playlistTimer_Tick(object sender, object e) { if (Images != null) { if (count == Images.Count - 1) count = 0; if (count < Images.Count) { count++; ImageRotation(); } }Step 9: Add a method of image Rotation
private void ImageRotation() { ImageSource.Source = new BitmapImage(new Uri("ms-appx:///Assets/" + Images[count])); }Step 10: Now add the code to Play, Pause, Previous and Next button's click event.
//Add code for "Play Button" click event private void playSlideshow_Click(object sender, RoutedEventArgs e) { { if (Images != null) { playlistTimer.Start(); } } } //Add code for "Pause Button" click event private void pauseSlideshow_Click(object sender, RoutedEventArgs e) { if (Images != null) { playlistTimer.Stop(); } } //Add code for "Previous Button" click event private void previousItem_Click(object sender, RoutedEventArgs e) { if (Images != null) { count--; if (count >= 0) { ImageRotation(); } else { count = Images.Count - 1; ImageRotation(); } } } //Add code for "Next Button" click event private void nextItem_Click(object sender, RoutedEventArgs e) { if (Images != null) { count++; if (count < Images.Count) { ImageRotation(); } else { count = 0; ImageRotation(); } } }
Output:
Technet Wiki

No comments:
Post a Comment