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

Windows Presentation Foundation Discussion :

Héritage d'une Window


Sujet :

Windows Presentation Foundation

  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Février 2007
    Messages
    96
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 96
    Par défaut Héritage d'une Window
    Bonjour,

    Je souhaite créer une Window afin de ne pas générer 36 milles fois de code.

    j'essaie donc d'hériter de Window.

    Voici le code de la classe.

    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
     
        public partial class STWindow : Window
        {
            static STWindow()
            {
                DefaultStyleKeyProperty.OverrideMetadata(typeof(STWindow), new FrameworkPropertyMetadata(typeof(STWindow)));
            }
     
     
            public STWindow()
                : base()
            {
                AllowsTransparency = true;
                WindowStyle = WindowStyle.None;
                this.AddHandler(Window.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Window_MouseLeftButtonDown));
            }
     
            private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                this.DragMove();
            }
        }

    Ensuite, j'appelle cette window dans mon application.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <test:STWindow
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:test="clr-namespace:MaLibairie;assembly=MaLibairie"
    	x:Class="MonApplication.MainWindow"
    	x:Name="Window" Background="Red"
    	Title="MainWindow"
    	Width="640" Height="480">
        <Grid x:Name="LayoutRoot" Background="Beige">
            <TextBlock Text="Coucou" Foreground="Aqua"/>
        </Grid>
    </test:STWindow>
    Cependant j'ai un petit problème,

    je ne vois pas ma grille et le contenu.

    Je dois faire quelque chose en particulier pour y arriver ?

    merci pour vos infos.

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Par défaut
    Salut,

    Il y a peut-être une solution proposées ici, mais je n'ai personnellement pas testé :
    http://www.developpez.net/forums/d89...w/#post5055663

    Tu peux lire l'ensemble de la discussion

  3. #3
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Février 2007
    Messages
    96
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 96
    Par défaut
    Merci pour l'info.

    Cela fonctionne pas mal du tout.

    J'ai néanmoins une autre question.

    J'ai créé une propriété "CornerRadius"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata();
    CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(int), typeof(STWindow), metadata);
    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
        <Style TargetType="{x:Type local:STWindow}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:STWindow}">
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding CornerRadius}">
                            <Grid ShowGridLines="True">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="10"/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="10"/>
                                </Grid.ColumnDefinitions>
                                
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="35"/>
                                    <RowDefinition />
                                    <RowDefinition Height="10"/>
                                </Grid.RowDefinitions>
    
                                <Grid Grid.Row="0" Grid.Column="1" ShowGridLines="True" Background="Beige">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="30"/>
                                        <ColumnDefinition/>
                                        <ColumnDefinition Width="100"/>
                                    </Grid.ColumnDefinitions>
                                </Grid>
    
                                <ContentControl 
                                    Grid.Row="1" Grid.Column="1" 
                                    Content="{TemplateBinding Content}" 
                                    HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalAlignment}" />
    
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    Ainsi je peux mettre une valeur pour effectuer un contour arrondi.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <test:STWindow
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:test="clr-namespace:MaLibairie;assembly=MaLibairie"
    	x:Class="MonApplication.MainWindow"
    	x:Name="Window" Background="Red"
    	Title="MainWindow" CornerRadius="10"
    	Width="640" Height="480">
        <Grid x:Name="LayoutRoot">
            <TextBlock Text="Coucou" Foreground="Aqua"/>
        </Grid>
    </test:STWindow>

    mais ma propriété est à 0 a démarrage de l'application.

    Comment puis je faire pour avoir la bonne valeur ?

    Merci

  4. #4
    Membre Expert
    Profil pro
    Inscrit en
    Décembre 2004
    Messages
    2 210
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2004
    Messages : 2 210
    Par défaut
    Je ne sais pas si ça vient de ça, mais, la propriété CornerRadius d'un Border n'est pas de type int mais de type CornerRadius

  5. #5
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Février 2007
    Messages
    96
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 96
    Par défaut
    Un grand merci m'sieur

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

Discussions similaires

  1. Héritage d'une classe thread
    Par SamCB500 dans le forum MFC
    Réponses: 4
    Dernier message: 07/07/2005, 15h35
  2. Problème d'héritage d'une méthode protégée
    Par shenron666 dans le forum C++
    Réponses: 9
    Dernier message: 28/04/2005, 23h17
  3. [debutant] affichier une windows dimensionnée
    Par adilou1981 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 11/02/2005, 11h49
  4. [héritage] héritage d'une variable static
    Par yaya44 dans le forum Langage
    Réponses: 14
    Dernier message: 29/09/2004, 13h36
  5. comment ecrire du texte dans une window application
    Par gaut dans le forum Autres éditeurs
    Réponses: 2
    Dernier message: 16/07/2003, 10h23

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