Ksdmg
Ksdmg

Reputation: 449

WPF MVVM - ViewModel First add controls to the same groupbox

I created my MVVM Pattern according to this SO Adding controls dynamically in wpf mvvm

My datatemplate looks like this:

    <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>

This is how my view looks like:

MyView but actually I want all the labels and textboxes in the same groupbox. How do I achieve this?

Upvotes: 0

Views: 378

Answers (1)

blindmeis
blindmeis

Reputation: 22445

remove the GroupBox from your DataTemplate and put the ItemsControl with the Collection of Product_Configurator:ModelParametersViewModels in a GroupBox

Upvotes: 1

Related Questions