【发布时间】:2016-11-18 10:28:47
【问题描述】:
我根据这个 SO Adding controls dynamically in wpf mvvm 创建了我的 MVVM 模式
我的数据模板如下所示:
<DataTemplate DataType="{x:Type Product_Configurator:ModelParametersViewModel}">
<GroupBox Grid.Row="1" x:Name="groupBox" Header="Standard" >
<Grid x:Name="grpStandard" >
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding AttributeName}" />
<TextBox Grid.Column="1" Style="{DynamicResource Configurator_Value_Box}" Text="{Binding EvalValue}"/>
</Grid>
</GroupBox>
</DataTemplate>
这是我的视图:
【问题讨论】:
-
只需从 DataTemplate 中删除 GroupBox 并将 ItemsControl 与 Product_Configurator:ModelParametersViewModels 的集合放在 GroupBox 中?
-
太棒了,不知何故它太明显了,我也看到了,谢谢。将其发布为答案,以便我标记它!