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 :

Wpf application: NavigationWindow class


Sujet :

C#

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Par défaut Wpf application: NavigationWindow class
    Bonjour tout le monde,
    Je sais que le thème de ma question a déjà été repris dans plusieurs discussion mais aucune d’entre elle ne répondent précisément à mon problème...
    Je suis en train d’améliorer une application Wpf codé en C# et xaml sous Microsoft Visual Studio Express 2012 for Windows Desktop.

    Je voudrais supprimer la barre de navigation du haut de ma fenêtre ainsi que de la maximiser au lancement de mon application. Pour cela je fais dans mon fichier xaml :

    Code xaml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <NavigationWindow x:Class="WpfAppTest.MainWindow"                  
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            WindowState="Maximized" 
            WindowStyle="None" 
            Title="MainWindow" Height="980 " Width="540" Source="Home.xaml" />

    Malgrès les deux propriétés WindowState="Maximized" et WindowStyle="None" la barre de navigation reste apparente et la fenêtre ne s’ouvre pas en grand. J’ai suivis plusieurs tutoriel qui répondaient à ma problématique mais à chaque fois ils utilisaient des class de type Window et non des NavigationWindow class. Dans mon cas j’ai essayé de changer ma class <NavigationWindow x:Class="WpfAppTest.MainWindow" en <Window x:Class="WpfAppTest.MainWindow" mais lorsque je lance l’application la propriété « source » n’est plus reconnue.

    Mon application contient plusieurs pages et je dois naviguer entre elles, je dois donc garder ma page « Home » comme type « page » : <Page x:Class="WpfAppTest.Home" et en tant que class page je n’ai pas accès à des propriétés telles que WindowState="Maximized" ou WindowStyle="None".

    Avez-vous une idée ou des conseils à me donner afin que je puisse résoudre mon problème ?
    Merci d’avance
    Geoffrey

  2. #2
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour GeoffreyLASSENA

    As-tu essaye ShowsNavigationUI,cela supprime donne une fen HomePage sans la barre de titre ="NavigationWindow Sample"(du NavigationWindow)
    qui s'affiche par defaut....

    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
     
    <NavigationWindow x:Class="WpfNavigationWin.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="NavigationWindow Sample"
            Height="980 " Width="540"
            Source="HomePage.xaml"
            WindowState="Maximized" 
            WindowStyle="None"
            ShowsNavigationUI="False">
     
        <!--Source="http://www.microsoft.com"-->
        <!--Source="Page1.xaml"-->
     
     
    </NavigationWindow>
    bon code...

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Par défaut
    Bonjour Mabrouki,

    Merci pour ta réponse, mais malheureusement j'avais déjà testé de mettre à false le ShowsNavigationUI mais rien ne change...

    Je ne vois vraiment pas comment régler ce problème

    Geoffrey

  4. #4
    Membre Expert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2009
    Messages
    2 056
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2009
    Messages : 2 056
    Par défaut
    T'es bien sur que la page que tu modifies est bien la page qui s'ouvre depuis le app.xaml.cs ?
    Si oui ne mets aucune source, pour voir si ca ne vient pas de la page "fille". Si c'est le cas il faudra mettre le code pour en savoir plus.

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Par défaut
    Bonjour micka,

    En fait dans mon App.xaml j'ai :
    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
               <Application x:Class="WpfAppTest.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="LoadingPage.xaml">
                </Application>
    Dans le App.xaml.cs je ne fait rien dans mon LoadingPage.xaml je fais:
         <Page x:Class="WpfAppTest.LoadingPage"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility     /2006" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          xmlns:custom="http://metro.mahapps.com/winfx/xaml/controls"
          mc:Ignorable="d" 
          ShowsNavigationUI="False" 
          d:DesignHeight="980" d:DesignWidth="540" Title="LoadingPage"  Loaded="Page_Loaded_2">

    Et c'est dans ma méthode Page_Loaded_2 que je crée ma nouvelle page Home : Home home = new Home(); NavigationService.Navigate(home);

    J'ai aussi un fichier MainWindow.xaml et lorsque je supprime la source cela ne change rien j'ai l'impression que cette page ne sert à rien.

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Par défaut
    Dans mon App.xaml je n'ai accès à aucune propriétés me permettant de maximiser ma fenêtre ainsi que de supprimer la barre de navigation. Dans ce App.xaml je fais StartupUri="LoadingPage.xaml" et LoadingPage est de type class Page donc je ne peux que faire ShowsNavigationUI="false" afin d'essayer de supprimer la bar de navigation mais cela ne change rien.. Dans mon LoadingPage je crée une nouvelle page Home de type class Page où je fais également ShowsNavigationUI="false" mais aucun changement.
    J'ai aussi un fichier MainWindow de type class NavigationWindow mais j'ai l'impression que ce MainWindow ne sert à rien et n'est appelé à aucun moments.

  7. #7
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    re
    C'est la confusion totale entre ce que tu as dans le 1er post et le 2e post !!!...

    Tu parles de Navigationwindow et maintenant tu dis que ta fenetre startup est un Page....

    Apparrement tu n'as pas compris le role du class NavigationWindow .Il permet une experience Navigateur dans les app Desktop comme le fait le Browser dans les app XBAP...
    Il sert juste à heberger les Pages....qui renvoie à d'autres pages....

    Mais c'est lui qu'on doit mettre dans StartupUri="MainWindow.xaml">

    Sa prop Source determine la 1er page à charger (equivalent de l'url de demarrage du browser IE)...


    Je reposte le code complet:
    application xaml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <Application x:Class="WpfNavigationWin.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
     
        </Application.Resources>
    </Application>
    application .cs :neant

    Navigation xaml (que j'ai appele par commodite MainWindow):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    <NavigationWindow x:Class="WpfNavigationWin.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="NavigationWindow Sample"
            Height="980 " Width="540"
            Source="HomePage.xaml"
            WindowState="Maximized" 
            WindowStyle="None"
            ShowsNavigationUI="False">
     
            <!-- Page Content  neant => tout est dnas la 1ere page indiquee par Source  -->
     
    </NavigationWindow>
    code xaml du Page HomePage.:

    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
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
     
    <Page x:Class="WpfNavigationWin.HomePage"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          mc:Ignorable="d" 
          d:DesignHeight="300" d:DesignWidth="300"
    	  Title="NavigationWindow"  >
        <!-- Page Content -->
        <DockPanel  
            Background="BlueViolet">
            <DockPanel
                DockPanel.Dock="Top">
                <!--bouton pour quitter ce navigationwindow -->
                <!--shutdown de l'appli -->
                <Button 
                    DockPanel.Dock="Right"
                    x:Name="Quit"
                    Content="Quit"
                    BorderBrush="Wheat"
                    Background="Red"
                    FontSize="18"
                    Click="Quit_Click">
                </Button>
            </DockPanel>
            <StackPanel 
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
                <!--navigation vers Page2 par uri -->
                <TextBlock
                VerticalAlignment="Center"
                HorizontalAlignment="Center"
                FontSize="14"
                Background="Yellow">
                 <Hyperlink 
                    Foreground="Red"
                    NavigateUri="Page2.xaml"
                   >
                    Hello !  Navigate to Page2
                </Hyperlink>
            </TextBlock>
            <Separator Height="60"></Separator>
     
     
                <!--navigation vers Page2 par par hyperlien -->
            <TextBlock
                VerticalAlignment="Stretch"
                HorizontalAlignment="Stretch"
                FontSize="14"
                Background="Red">
                <Hyperlink
                    Foreground="White"
                    Click="Hyperlink_Click">
                    Hello ! Navigate to  Page2
                </Hyperlink>
            </TextBlock>
            </StackPanel>
        </DockPanel >
    </Page>
    code behind .cs de du Page HomePage.:
    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
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
     
    namespace WpfNavigationWin
    {
        /// <summary>
        /// Logique d'interaction pour Page1.xaml
        /// </summary>
        public partial class HomePage : Page
        {
            public HomePage()
            {
                InitializeComponent();
            }
     
     
            private void Hyperlink_Click(object sender, RoutedEventArgs e)
            {
                // Get a reference to the NavigationService that navigated to this Page
                NavigationService ns = this.NavigationService;
     
                // Navigate to the page, using the NavigationService
                Page page2 = new Page2();
                this.NavigationService.Navigate(page2 );
     
            }
     
            private void Quit_Click(object sender, RoutedEventArgs e)
            {
                App.Current.Shutdown();
            }
        }
    }
    code xaml du Page2 :
    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
     
    <Page x:Class="WpfNavigationWin.Page2"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          mc:Ignorable="d" 
          d:DesignHeight="300" d:DesignWidth="300"
    	Title="Page2"
          >
        <DockPanel
            Background="Azure">
            <TextBlock
                DockPanel.Dock="Bottom"
                VerticalAlignment="Center"
                HorizontalAlignment="Center"
                FontSize="14"
                Background="Crimson">
                <Hyperlink 
                    Foreground="White"
                    NavigateUri="HomePage.xaml">
                    Hello!   Navigate to HomePage
                </Hyperlink>
            </TextBlock>
     
     
        </DockPanel>
    </Page>
    pas de code .cs du Page2....

    Sans le bouton Quit il n' y a aucun moyen de fermer NavigationWindow pour quitter l'applicalion a cause du WindowStyle="None"...Si en plus tu l'affiche en plein ecran...!...
    bon code....

  8. #8
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 5
    Par défaut
    Merci de ta réponse,
    En effet ce n'est pas trop clair avec la class NavigationWindow surtout qu'en voyant que mon MainWindow de type NavigationWindow n'étant jamais appelé j'ai tenté de le supprimer et la mon application tourne normalement j'arrive toujours à naviguer entre mes pages.
    Voici le code de mon application:

    <Application x:Class="WpfAppTest.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="LoadingPage.xaml">
    </Application>

    Dans LoadingPage.xaml.cs (LoadingPage de type Page et non NavigationWindow) je copie une base de donnée en ligne et je crée une nouvelle page "Home". Je peux ensuite naviguer sans problème entre mes pages et tout ça en ayant uniquement mon App.xaml de type Application et toute les autres pages de type Page...

Discussions similaires

  1. Android Market : les applications seront classées par type de public
    Par Gordon Fowler dans le forum Actualités
    Réponses: 4
    Dernier message: 26/11/2010, 09h18
  2. Mettre élément WPF depuis une classe
    Par juliensmarties dans le forum Windows Presentation Foundation
    Réponses: 6
    Dernier message: 07/07/2010, 10h28
  3. application web + class en js
    Par abir001 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 07/06/2010, 19h43
  4. classe applicative et classe metier ?
    Par sali dans le forum Diagrammes de Classes
    Réponses: 7
    Dernier message: 08/07/2009, 23h52
  5. NavigationWindow : Classe perso, redéfinission de style
    Par dev01 dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 29/02/2008, 12h14

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