2008-11-25 8 views
16

Je suis actuellement en train de jouer avec WPF et maintenant je me demande quelle serait la disposition pour une fenêtre dataentry typique (plus de 20 textboxes et autres).WPF Meilleures pratiques pour la fenêtre DataEntry

atm i`m en utilisant un objet de grille comme celui-ci (échantillon de base)

<Grid Margin="2,2,2,2"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto"></ColumnDefinition> 
      <ColumnDefinition Width="*"></ColumnDefinition> 
     </Grid.ColumnDefinitions> 

     <Grid.RowDefinitions > 
      <RowDefinition Height="Auto"></RowDefinition> 
      <RowDefinition Height="Auto"></RowDefinition> 
      <RowDefinition Height="Auto"></RowDefinition> 
      <RowDefinition Height="Auto"></RowDefinition> 
      <RowDefinition Height="Auto"></RowDefinition> 
      <RowDefinition Height="Auto"></RowDefinition> 
      <RowDefinition Height="Auto"></RowDefinition> 
      <RowDefinition Height="Auto"></RowDefinition> 
     </Grid.RowDefinitions> 

      <Label Grid.Row="0" Grid.Column="0">Vorname:</Label> 
      <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=Surname, UpdateSourceTrigger=PropertyChanged}" ></TextBox> 

      <Label Grid.Row="1" Grid.Column="0">Nachname:</Label> 
      <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=ChristianName, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

      <Label Grid.Row="2" Grid.Column="0">Strasse (Wohnsitz):</Label> 
      <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=Street1, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

      <Label Grid.Row="3" Grid.Column="0">Ort (Wohnsitz):</Label> 
      <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=Town1, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

      <Label Grid.Row="4" Grid.Column="0">Postleitzahl (Wohnsitz):</Label> 
      <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Path=PostalCode1, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

      <Label Grid.Row="5" Grid.Column="0">Bundesland (Wohnsitz):</Label> 
      <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding Path=State1, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

      <Label Grid.Row="6" Grid.Column="0">Land (Wohnsitz):</Label> 
      <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Path=Country1, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

      <Label Grid.Row="7" Grid.Column="0">Zusatz (Wohnsitz):</Label> 
      <TextBox Grid.Row="7" Grid.Column="1" Text="{Binding Path=AdditionalAdrInfo1, UpdateSourceTrigger=PropertyChanged}"></TextBox> 

    </Grid> 

En gros, cela répond à tous mes besoins de mise en page, mais si je veux changer quelque chose, comme l'ajout d'une nouvelle zone de texte dans la ligne 3 ?

actuellement je dois changer chaque propriété Grid.Row supérieure à 3, mais qui ne peut pas être la manière WPF prévue !?

Comment les autres mettent-ils en forme des fenêtres d'entrée de données complexes?

tia

Répondre

3

Certaines personnes utilisent StackPanel imbriquées s pour « résoudre » ce problème, mais à mon humble avis qui introduit juste un autre problème (météorisation code). Je pense que la meilleure façon de résoudre cela est d'écrire votre propre panneau qui répartit les enfants consécutivement dans des colonnes. Je l'ai fait sur un projet précédent et il a un certain nombre d'avantages:

  • Plus lisible et laconique XAML
  • plus facile à maintenir XAML
  • Performances plus rapides

L'usage avait l'air quelque chose comme ça :

<local:FieldPanel> 
    <Label>Field 1:</Label> 
    <TextBox/> 

    <Label>Field 2:</Label> 
    <TextBox/> 

    <Label>Field 3:</Label> 
    <TextBox/> 
</local:FieldPanel>