题
目前,我正在玩弄WPF现在我不知道什么会是个典型的数据录入过程窗口(20+文本框和东西).
atm我使用网格的对象这样的(基本样本)
<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>
这基本上满足了我所有的布局需要,但是如果我想要改变的东西,比如增加一个新的文本在第3行?
目前我必须要改变每一个电网。行性大3,但这不能以预期的WPF方式!?
怎么其他的布局复杂的数据录入过程windows?
tia
解决方案
卡尔Shifflett还有一个很好的方法来LOB形式在WPF: http://karlshifflett.wordpress.com/2008/10/23/wpf-silverlight-lob-form-layout-searching-for-a-better-solution/
其他提示
就个人而言,我是一个巨大风扇的AutoGrid: http://www.codeplex.com/wpfcontrib/Wiki/View.aspx?title=AutoGrid&referringTitle=Home
一些人使用嵌套 StackPanel
s"解决"这一问题,但恕我直言,这只是介绍了另一个问题(代码膨胀).我认为最好的方式来解决这个是写你自己的小组,规定了儿童连续列。我这么做是对前一项目,它具有若干优点:
- 更具可读性和简洁XAML
- 更易于维护XAML
- 快演
所使用的看起来是这样的:
<local:FieldPanel>
<Label>Field 1:</Label>
<TextBox/>
<Label>Field 2:</Label>
<TextBox/>
<Label>Field 3:</Label>
<TextBox/>
</local:FieldPanel>
不隶属于 StackOverflow