【问题标题】:WPF MVVM - ViewModel First add controls to the same groupboxWPF MVVM - ViewModel 首先将控件添加到同一个 groupbox
【发布时间】: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 中?
  • 太棒了,不知何故它太明显了,我也看到了,谢谢。将其发布为答案,以便我标记它!

标签: .net wpf xaml mvvm


【解决方案1】:

从您的 DataTemplate 中删除 GroupBox 并将 ItemsControl 与 Product_Configurator:ModelParametersViewModels 的集合放在 GroupBox 中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 2012-05-09
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多