IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

WinRT Discussion :

Mon premier slide show sous Win8 [Débutant]


Sujet :

WinRT

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    192
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 192
    Points : 79
    Points
    79
    Par défaut Mon premier slide show sous Win8
    Bonjour,

    Je débute dans le dev sur mobile pour Winsows 8. J'ai suivi ce tuto (plutôt bien fait).
    Je l'ai fait en C#/XAML. Je suis toutes les instructions jusqu'au point 7. Quand je lance l'application, j'ai bien une image affichée, mais je ne trouve pas comment passer l'image suivante, "slider"...
    Est-ce que qq a déjà fait ce tuto ou aurait une idée?

    Voici le code C#
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Core;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    using Windows.UI.Xaml.Media.Imaging;
    using Windows.Media.PlayTo;
    using Windows.UI;
    using Windows.Storage;
    using Windows.Storage.Streams;
     
    // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
     
    namespace SlideShow
    {
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class MainPage : Page
        {
     
            private PlayToManager ptm = null;
            private DispatcherTimer timer = null;
            private IReadOnlyList<StorageFile> imageList = null; // Liste des images a afficher
            private int imageIdx = -1; // index de l'image courante
            private Image currentPlayer = null; // afficheur d'image courant
            private bool isStreaming; // True if Streaming
            private CoreDispatcher messageDispatcher = Window.Current.CoreWindow.Dispatcher;
     
            public MainPage()
            {
                this.InitializeComponent();
            }
     
            /// <summary>
            /// Invoked when this page is about to be displayed in a Frame.
            /// </summary>
            /// <param name="e">Event data that describes how this page was reached.  The Parameter
            /// property is typically used to configure the page.</param>
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                this.ptm = PlayToManager.GetForCurrentView();
                this.ptm.SourceRequested += this.SourceRequested;
                this.ptm.SourceSelected += this.SourceSelected;
     
                this.timer = new DispatcherTimer();
                this.timer.Interval = new TimeSpan(0, 0, 5);
                this.timer.Tick += TimeoutElapsed;
     
                this.StartSlideShow();
            }
     
            /// <summary>
            /// Récupère la liste des images et démarre le slideShow
            /// </summary>
            async private void StartSlideShow()
            {
                var resultsLibrary = await Windows.Storage.KnownFolders.PicturesLibrary.GetFilesAsync();
                this.imageList = resultsLibrary;
     
                if (imageList.Count > 0)
                {
                    SetImageSource(this.ImagePlayer1, this.GetNextImage());
                }
                else
                {
                    MessageBlock.Text = "No image found in the Pictures Library";
                }
     
            }
     
            /// <summary>
            /// Affiche une image dans une vue
            /// </summary>
            /// <param name="image">vue ou l'image est affichée</param>
            /// <param name="imageFile">file image à afficher</param>
            async private void SetImageSource(Image imagePlayer, StorageFile imageFile)
            {
                // ouvert de l'image dans un object bitmap
                IRandomAccessStream imageStream = await imageFile.OpenAsync(FileAccessMode.Read);
     
                BitmapImage imageBitmap = new BitmapImage();
                imageBitmap.SetSource(imageStream);
     
                // Set l'image au player
                imagePlayer.Source = imageBitmap;
            }
     
            /// <summary>
            /// Récupère l'image suivante
            /// </summary>
            /// <returns></returns>
            private StorageFile GetNextImage()
            {
                this.imageIdx++;
                if (this.imageIdx >= this.imageList.Count)
                {
                    this.imageIdx = 0;
                }
     
                return imageList[this.imageIdx];
            }
     
            private void ShowImage(Image imagePlayer)
            {
                this.currentPlayer = imagePlayer;
                Image otherImagePlayer = (imagePlayer.Name == "ImagePlayer1") ? this.ImagePlayer2 : this.ImagePlayer1;
     
                // Met en cache la prochaine image
                SetImageSource(otherImagePlayer, GetNextImage());
     
                if (this.isStreaming)
                {
                    try
                    {
                        otherImagePlayer.PlayToSource.PlayNext();
                    }
                    catch (Exception )
                    {
                    }
                }
                else
                {
                    otherImagePlayer.Visibility = Visibility.Collapsed;
                    imagePlayer.Visibility = Visibility.Visible;
                }
     
                this.currentPlayer = otherImagePlayer;
                this.timer.Start();
     
            }
     
            /// <summary>
            /// Pass image source to play to
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            async private void SourceRequested(PlayToManager sender, PlayToSourceRequestedEventArgs e)
            {
                e.SourceRequest.SetSource(currentPlayer.PlayToSource);
     
                // Set Play To Source next properties
                ImagePlayer1.PlayToSource.Next = ImagePlayer2.PlayToSource;
                ImagePlayer2.PlayToSource.Next = ImagePlayer1.PlayToSource;
     
                await messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // Stop slide show
                    timer.Stop();
                });
            }
     
     
            /// <summary>
            /// Set up Streamin if device selected
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            async private void SourceSelected(PlayToManager sender, PlayToSourceSelectedEventArgs e)
            {
                WriteMessageText("Streaming...");
                this.isStreaming = true;
                await this.messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        //hide local image players
                        this.ImagePlayer1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        this.ImagePlayer2.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
     
                        // start slide show again with the next image
                        timer.Start();
                    });
            }
     
            async private void WriteMessageText(String message, bool isOverwrite = false)
            {
                await messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (isOverwrite)
                        {
                            this.MessageBlock.Text = message;
                        }
                        else
                        {
                            this.MessageBlock.Text += message;
                        }
                    });
            }
     
            private void TimeoutElapsed(Object sender, Object e)
            {
                this.ShowImage(currentPlayer);
            }
        }
    }
    et le XAML
    Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <Page
        x:Class="SlideShow.MainPage"
        IsTabStop="false"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:SlideShow"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
     
        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <StackPanel>
                <TextBlock x:Name="MessageBlock" Width="300"/>
            </StackPanel>
            <StackPanel>
                <Image x:Name="ImagePlayer1" Height="400" Width="600"/>
                <Image x:Name="ImagePlayer2" Height="400" Width="600"/>
            </StackPanel>
        </Grid>
    </Page>

  2. #2
    Membre émérite
    Avatar de Samuel Blanchard
    Homme Profil pro
    Expert .NET
    Inscrit en
    Février 2010
    Messages
    1 504
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France

    Informations professionnelles :
    Activité : Expert .NET

    Informations forums :
    Inscription : Février 2010
    Messages : 1 504
    Points : 2 682
    Points
    2 682
    Par défaut
    Juste pour info, regarde du coté du Timer (il semblerait que c'est lui qui effectue le changmeent d'image).
    .
    Pas de question technique en MP, merci.
    .
    Un emulator Gameboy Color pour Windows Phone ?
    c'est moi qui l'ai fait

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    192
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 192
    Points : 79
    Points
    79
    Par défaut
    Oui effectivement, le code n'était pas bon au niveau du timer. J'ai réussi à le faire marcher.
    Merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2007] Mon premier problème sous Excel
    Par Foreverpro dans le forum Excel
    Réponses: 2
    Dernier message: 01/03/2013, 20h50
  2. Aide pour mon premier script sous linux
    Par bomonde dans le forum Shell et commandes GNU
    Réponses: 1
    Dernier message: 21/10/2010, 14h27
  3. Mon premier programme sous éclipse
    Par dot-_-net dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 09/07/2008, 15h26
  4. mon premier programme sous eclipse
    Par ninours23 dans le forum Eclipse C & C++
    Réponses: 3
    Dernier message: 28/02/2008, 14h29
  5. mon premier sous rapport
    Par karibouxe dans le forum iReport
    Réponses: 7
    Dernier message: 01/08/2006, 16h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo