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 - Propriété 'Content' définie plusieurs fois [Débutant]


Sujet :

C#

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Août 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Août 2017
    Messages : 71
    Points : 25
    Points
    25
    Par défaut WPF - Propriété 'Content' définie plusieurs fois
    Bonjour à tous.

    J'ai créé mon tableau de données de type UnifromGrid avec mes datas de type Binding (c'est une liste contenant mes objets de ma classe, objets créé avec mes lignes SQL).

    Ma liste est scrolalble, c'est ce que je voulais, c'est top.

    Maintenant j'aimerais ajouter en haut de la liste scrollable un bouton fixe, et en bas de la liste scrollable un label, fixe aussi. Je veux toujours voir ces éléments même quand je scroll.

    Malheureusement j'ai une erreur "La propriété "Content" est définie plusieurs fois :

    Mon Code 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
    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
    <Window
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:Plutus" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Plutus.MainWindow"
            Title="MainWindow" Height="523.725" Width="898" Background="#FF3A3939" WindowStartupLocation="CenterScreen" WindowState="Maximized">
        <Window.Resources>
            <Style TargetType="ScrollBar">
                <Setter Property="Width" Value="35"/>
            </Style>
        </Window.Resources>
     
        <Button></Button>
     
        <ScrollViewer VerticalScrollBarVisibility="Auto" >
            <ItemsControl x:Name="lvDataBinding" HorizontalContentAlignment="Stretch" BorderThickness="0" Margin="10" Grid.Row="3" Background="{x:Null}" ItemsSource="{Binding}" Foreground="White">
                <ItemsControl.ItemTemplate>
                    <DataTemplate DataType="{x:Type local:CL_Operation}">
                        <Border BorderBrush="White" BorderThickness="1" CornerRadius="3" Margin="0,3" Grid.ColumnSpan="0" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Top">
                            <Grid Width="{Binding strWidth}" Height="60" Background="Transparent" Margin="0,1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="0.08*" />
                                    <ColumnDefinition Width="0.1*" />
                                    <ColumnDefinition Width="0.1*" />
                                    <ColumnDefinition Width="0.2*" />
                                    <ColumnDefinition Width="0.1*" />
                                    <ColumnDefinition Width="0.2*" />
                                    <ColumnDefinition Width="0.1*" />
                                    <ColumnDefinition Width="0.2*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <UniformGrid  Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Background="#FFFF8200">
                                    <TextBlock Text="{Binding strPriorite}" FontSize="36" Foreground="Red" HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold" />
                                    <TextBlock Text="{Binding strSsSect}" FontSize="12" Foreground="Black"  HorizontalAlignment="Center" VerticalAlignment="Bottom" FontWeight="Bold" />
                                </UniformGrid>
                                <UniformGrid  Grid.Column="1" Grid.Row="0" Grid.RowSpan="3">
                                    <TextBlock Text="{Binding strRetardAvanceText}" FontSize="28" Foreground="{Binding scbColorRetardAvance}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                </UniformGrid>
                                <UniformGrid Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="2" Grid.RowSpan="2">
                                    <UniformGrid.Style>
                                        <Style TargetType="{x:Type UniformGrid}">
                                            <Style.Triggers>
                                                <Trigger Property="IsMouseOver" Value="true">
                                                    <Setter Property="Background" Value="Gray"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </UniformGrid.Style>
                                    <TextBlock Text="{Binding strNoOfOp}" FontSize="28" Foreground="White" FontWeight="Bold" MouseLeftButtonUp="Test"/>
                                </UniformGrid>
                                <UniformGrid  Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="3">
                                    <TextBlock Text="{Binding strDescriptionOp}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                                <UniformGrid Grid.Column="4" Grid.Row="0">
                                    <TextBlock Text="{Binding strNoArticle}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                                <UniformGrid  Grid.Column="4" Grid.Row="1">
                                    <TextBlock Text="{Binding strDateFormatee}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                                <UniformGrid Grid.Column="5" Grid.Row="0">
                                    <TextBlock Text="{Binding strPcesPoste}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                                <UniformGrid  Grid.Column="5" Grid.Row="1">
                                    <TextBlock Text="{Binding strTpsPoste}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                                <UniformGrid  Grid.Column="6" Grid.Row="0">
                                    <TextBlock Text="{Binding strTempsPoste}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                                <UniformGrid  Grid.Column="6" Grid.Row="1">
                                    <TextBlock Text="{Binding strClient}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                                <UniformGrid  Grid.Column="6" Grid.Row="2" Grid.ColumnSpan="2">
                                    <TextBlock Text="{Binding strTypeOp}" FontSize="14" Foreground="White"/>
                                </UniformGrid>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Columns="2"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </ScrollViewer>
     
     
     
    </Window>
    Comment je peux ajouter mon bouton et mes labels ?

    Merci

  2. #2
    Membre à l'essai
    Femme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2014
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Octobre 2014
    Messages : 9
    Points : 20
    Points
    20
    Par défaut
    Bonjour Fellerson,

    pour ton problème, je suppose que ta balise parent Window a une propriété "Content".
    Tu ne l'a défini pas explicitement cependant les contrôles graphiques que tu mets entre <Window> et </Window> sont insérés dans <Window.Content>.
    Or, tu ne peux avoir qu'un seul controle graphique enfant de Content.
    Actuellement dans ton code, tu as 1 bouton, 1 scrollviewer qui sont enfants de Content, d’où l'erreur.

    Tu dois englober ton bouton / scrollviewer dans un autre contrôle comme un Grid, ou un StackPanel (je ne cite que cela car je n'en connais pas d'autre en WPF).

    bonne journée,
    Mud

  3. #3
    Membre chevronné
    Homme Profil pro
    edi
    Inscrit en
    Juin 2007
    Messages
    898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : edi

    Informations forums :
    Inscription : Juin 2007
    Messages : 898
    Points : 1 915
    Points
    1 915
    Par défaut
    Il ne peut y avoir qu'un seul objet graphique dans la fenêtre ; mais cet objet peut être un conteneur d'objets graphiques. Dans la fenêtre tu peux mettre une Grid avec trois lignes (Row) :
    - dans le première ton bouton ;
    - dans la deuxième le ScrollViewer avec ta liste d'item ;
    - dans la troisième le label.
    Il doit falloir mettre une hauteur pour la deuxième ligne afin de forcer l'utilisation du scroll.

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Août 2017
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Août 2017
    Messages : 71
    Points : 25
    Points
    25
    Par défaut
    Ok c'est top, j'ai compris !

    Merci.

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

Discussions similaires

  1. Réponses: 6
    Dernier message: 17/12/2014, 00h37
  2. La propriété Content est définie plusieurs fois
    Par mahdi26_ca dans le forum Silverlight
    Réponses: 4
    Dernier message: 02/04/2011, 19h04
  3. [MasterPages] Réutiliser un même Content plusieurs fois
    Par SaumonAgile dans le forum ASP.NET
    Réponses: 14
    Dernier message: 23/09/2008, 16h36
  4. [XSLT] variable définie plusieurs fois dans la même portée
    Par dhallennem dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 06/02/2008, 15h48
  5. Réponses: 6
    Dernier message: 30/11/2006, 18h15

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