Précédent   Forum du club des développeurs et IT Pro > Dotnet > Développement Windows > WinRT
WinRT Forum d'entraide sur le développement d'applications Metro pour Windows 8 avec WinRT
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 20/06/2012, 17h52   #1
yupa
Membre du Club
 
Inscription : mai 2005
Messages : 192
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 192
Points : 44
Points : 44
Par défaut Changement de page: écran noir

Bonjour

Encore moi qui patauge dans ma découverte de dev sous windows8

Je me suis inspiré du code de ce tuto (plutôt bien fait), pour faire un écran de chargement avant l'affichage d'images:
Première question, dans ces tutos, il est dit que les classes dans Commom étaient automatiquement générées par visual studio (comme LayoutAwarePage). Dans Common je n'ai qu'un seul fichier StandardStyles.xaml. Pourquoi?

Deuxième point,
dans mon application je commence donc par lire dans un fichier un certain nombre d'information (des offset d'image). Pendant ce chargement, j'affiche un petit écran de chargement (comme dans le tuto) :
Code c# :
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
public sealed partial class ExtendedSplachScreen : UserControl
    {
        private SplashScreen splashScreen; // Variable to hold the splash screen object.
        private MZHandler mzHandler = null;
 
        public ExtendedSplachScreen(SplashScreen splash, MZHandler mozzoHandeler)
        {
            this.splashScreen = splash;
            this.mzHandler = mozzoHandeler;
 
            this.InitializeComponent();
 
            this.extendedSplashImage.SetValue(Canvas.LeftProperty, this.splashScreen.ImageLocation.X);
            this.extendedSplashImage.SetValue(Canvas.TopProperty, this.splashScreen.ImageLocation.Y);
            this.extendedSplashImage.Height = this.splashScreen.ImageLocation.Height;
            this.extendedSplashImage.Width = this.splashScreen.ImageLocation.Width;
 
            AttachHandler();
 
            ExecuteParsing();
        }
 
        private void ExecuteParsing()
        {
            if (this.mzHandler != null)
            {
                this.mzHandler.ParseMZFileAsyncr();
            }
        }
 
        internal void splashScreen_Dismissed(SplashScreen sender, object args)
        {
 [...]
        }
 
        void mzHandlerPageLoadProgress(object sender, MZHandler.PageLoadEnventArgs e)
        {
            txtLoading.Text = "Chargement page " + e.nbPage;
        }
        void mzHandlerPagesLoaded(object sender, MZHandler.PageLoadEnventArgs e)
        {
            Navigate(this.mzHandler);
        }
 
        void AttachHandler()
        {
            this.splashScreen.Dismissed += splashScreen_Dismissed;
            this.mzHandler.LoadMZFileProgress += mzHandlerPageLoadProgress;
            this.mzHandler.PagesLoaded += mzHandlerPagesLoaded;
        }
 
        void DetachHandler()
        {
            [...]
        }
 
        void Navigate(MZHandler mzHandler)
        {
            DetachHandler();
            var rootFrame = new Frame();
            rootFrame.Navigate(typeof(MainPage), mzHandler);
 
            // Place the frame in the current Window and ensure that it is active
            Window.Current.Content = rootFrame;
            Window.Current.Activate();
        }
    }
Jusque là, pas de problème.

C'est au moment d'afficher la page "MainPage" que ca ne va pas. 9 fois sur 10, j'ai un écran noir . Je suis quasiment sur que mon objet MainPage est bien construit (dans une version précédente, je l'affichais sans problème). J'ai passé la journée à chercher d'ou ca pouvais venir (break pont, pas à pas...), je ne vois pas pourquoi j'ai un écran noir et pas ma page.
Voici le xaml de mainpage:
Code xaml :
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
<Page
    x:Class="MZReader01.MainPage"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MZReader01"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
 
    <!-- Ressource de la page -->
    <Page.Resources>
        <!-- Style pour le bouton zoom -->
        <Style x:Key="ZoomAppBarButtonStyle" TargetType="Button" BasedOn="{StaticResource AppBarButtonStyle}">
            <Setter Property="AutomationProperties.AutomationId" Value="ZoomAppBarButton"/>
            <Setter Property="AutomationProperties.Name" Value="Zoom"/>
            <Setter Property="Content" Value="&#xE12E;"/>
        </Style>
        <!-- Template pour l'affichage d'une page avec l'image de la page (Thumbnail/Mini) et un texte -->
        <DataTemplate x:Key="PageTemplate">
            <Border Background="Orange">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="300"/>
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Column="0">
                        <StackPanel x:Name="ImagePanel" Height="669" Margin="20,10,10,0" VerticalAlignment="Top" Width="1036" HorizontalAlignment="Center" Orientation="Horizontal">
                            <Image x:Name="ImageView" Source="{Binding ImageData}" Margin="0,10,10,10"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Bottom"/>
                        </StackPanel>
                    </Grid>
                    <Grid Grid.Column="1">
                        <TextBlock x:Name="ImageNameFied" Text="{Binding PageText}" TextWrapping="Wrap" Margin="10,10,10,10" 
                           FontSize="24"
                           Foreground="AliceBlue"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"/>
                    </Grid>
                </Grid>
            </Border>
        </DataTemplate>
        <!-- Instanciation du template selector pour le flipview -->
        <local:MZPageTemplateSelector x:Key="pageTemplateSelector" PageTemplate="{StaticResource PageTemplate}"/>
    </Page.Resources>
 
    <!-- Tool bar en bas de la page -->
    <Page.BottomAppBar>
        <AppBar IsOpen="True" HorizontalContentAlignment="Center" IsSticky="True">
            <Grid>
                <StackPanel Orientation="Horizontal">
                    <Button x:Name="PreviousButton" Style="{StaticResource PreviousAppBarButtonStyle}" Click="PreviousButton_Click"/>
                    <Button x:Name="ZoonButton" Style="{StaticResource ZoomAppBarButtonStyle}" Click="ZoonButton_Click"/>
                    <Button x:Name="NextButton" Style="{StaticResource NextAppBarButtonStyle}" Click="NextButton_Click"/>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>
 
    <!-- Grid principal -->
    <Grid x:Name="MainGrid" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <FlipView x:Name="pageFlipView" ItemTemplateSelector="{StaticResource pageTemplateSelector}"></FlipView>
    </Grid>
</Page>
(Remarquer la forte ressemblance avec mon topic précédent

Je patine, je tourne en rond... Est ce qq un aurait juste une petite idée pour orienter mes cherches.
Merci d'avance
yupa est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/06/2012, 11h40   #2
yupa
Membre du Club
 
Inscription : mai 2005
Messages : 192
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 192
Points : 44
Points : 44
Bon je vais me répondre

Je problème venait du fait que mon chargement se produisait très rapidement, même trop.
C'est à dire que la page ExtendedSplachScreen n'était pas encore affichée que le traitement était déjà fini et que j'essayais d'afficher la page suivante. Du coup écran noir. Évident une fois qu'on a mis les brackpoint aux bons endroits et vérifié sa callstack

Par rapport au code que j'ai posté la correction est simple:
La fonction qui fait le traitement de load ne doit pas être appelée dans le constructeur de ExtendedSplachScreen, car la page n'ai pas encore affichée à ce moment la. Il faut l'appeler dans L'event Loaded :
Code xaml :
1
2
3
4
5
6
7
8
9
<Page
    x:Class="MozzoView.View.MozzoSplashScreenLoading"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MozzoView.View"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" Loaded="ScreenLoaded">
Code c# :
1
2
3
4
5
6
7
private void ScreenLoaded(object sender, RoutedEventArgs e)
{
    if (this.mzHandler != null)
    {
        this.mzHandler.ParseMZ();
    }
}

Avec ca, même si le traitement de chargement est très/trop rapide, il n'y a plus d'écran noir et la page suivante est affichée.
En espérant que ca pourra servir a d'autres ^^
yupa est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 11h13.


 
 
 
 
Partenaires

Hébergement Web