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

C# Discussion :

Frame.Navigate ou NavigationService.Navigate ne marchent pas.


Sujet :

C#

  1. #1
    Candidat au Club
    Homme Profil pro
    Etudiant
    Inscrit en
    Octobre 2015
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Etudiant

    Informations forums :
    Inscription : Octobre 2015
    Messages : 4
    Points : 4
    Points
    4
    Par défaut Frame.Navigate ou NavigationService.Navigate ne marchent pas.
    Hello les gens,

    Je sollicite votre aide. Etant débutant dans les applications windows phone.
    J'essaye lors d'un click sur un bouton ( Connexion / Inscription ) changer de views. ( ConnexionView ou InscriptionView ).

    Voila mon code MainPage.xaml

    Code : 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
    <Grid>
            <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FF563AA0" Offset="1"/>
                </LinearGradientBrush>
            </Grid.Background>
     
            <ContentControl Content="{Binding CurrentViewModel}" />
     
            <Button
                Command="{Binding ConnexionViewCommand}"
                x:Name="Connexion_button" 
                HorizontalAlignment="Left" 
                Margin="90,308,0,0"
                Content="Login" 
                VerticalAlignment="Top" 
                Width="282"/>
            <Button 
                Command="{Binding InscriptionViewCommand}"
                x:Name="Create_account" 
                HorizontalAlignment="Left" 
                Margin="90,446,0,0"
                Content="Create Account" 
                VerticalAlignment="Top" 
                Width="282"/>
        </Grid>
    Voila mon code MainViewModel.cs

    Code : 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
        public class MainViewModel : ViewModelBase
        {
            private ViewModelBase _currentViewModel;
     
            readonly static ConnexionViewModel _ConnexionViewModel = new ConnexionViewModel();
            readonly static InscriptionViewModel _InscriptionViewModel = new InscriptionViewModel();
            readonly static MainPageViewModel _MainPageViewModel = new MainPageViewModel();
     
     
            public ViewModelBase CurrentViewModel
            {
                get
                {
                    return _currentViewModel;
                }
                set
                {
                    if (_currentViewModel == value)
                        return;
                    _currentViewModel = value;
                    RaisePropertyChanged("CurrentViewModel");
                }
            }
            public ICommand ConnexionViewCommand { get; private set; }
            public ICommand InscriptionViewCommand { get; private set; }
     
            public MainViewModel()
            {
                CurrentViewModel = MainViewModel._MainPageViewModel;
                ConnexionViewCommand =  new RelayCommand(() => ExecuteConnexionViewCommand());
                InscriptionViewCommand = new RelayCommand(() => ExecuteInscriptionViewCommand());
            }
     
        private void ExecuteConnexionViewCommand()
        {
            Frame.Navigate(typeof(ConnexionView));
            NavigationService.Navigate(new Uri("/ConnexionView.xaml", UriKind.Relative));
            MessageBox.Show("CONNEXION");
        }
     
        private void ExecuteInscriptionViewCommand()
        {
            Frame.Navigate(typeof(InscriptView));
            NavigationService.Navigate(new Uri("/InscriptionView.xaml", UriKind.Relative));
            MessageBox.Show("REGISTER");
        }
     
        }
    Les fonctions sont bien call ( MessageBox.Show), donc lors d'un click , ca rentre bien dans les fonctions. Par contre, le Frame.navigate ou NavigationService.Navigate ne marche pas. Pouvez vous me renseigner?

    Bien sur j'ai laissé les deux pour vous montrer ce que j'ai testé.

  2. #2
    Candidat au Club
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Juillet 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2013
    Messages : 2
    Points : 3
    Points
    3
    Par défaut navigationService
    Le main est déjà une Frame, la solution serait plutôt d'encapsuler tes composants dans <Frame></Frame> dans la fenêtre main de l'application store comme cela toutes les vues que tu construis après seront appelables par Frame.Navigate.
    Mais tu peux aussi utiliser Galasoft MVVM comme template, ce sera encore plus facile.

Discussions similaires

  1. [Débutant] Frame et barre de navigation
    Par DoogT dans le forum Windows Presentation Foundation
    Réponses: 1
    Dernier message: 26/02/2013, 10h05
  2. Réponses: 2
    Dernier message: 09/10/2009, 19h53
  3. Réponses: 4
    Dernier message: 01/10/2005, 13h52
  4. [VB.NET] Les évènements ne marchent pas
    Par Dnx dans le forum ASP.NET
    Réponses: 6
    Dernier message: 28/01/2005, 12h54
  5. [FASM] Interruptions BIOS ne marchent pas sous XP
    Par LaPatoshe dans le forum Assembleur
    Réponses: 2
    Dernier message: 01/12/2004, 18h44

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