How can I dynamically create a list of label and textboxes in WPF?

前端 未结 2 1106
北荒
北荒 2021-01-20 16:05

I am trying, and failing, to create a list of labels and text boxes in WPF. I am a ASP.NET developer and the XAML experience is slightly overwhelming me at the moment... I

相关标签:
2条回答
  • 2021-01-20 16:36

    There's absolutely no need to use a DataGrid for something as simple as this. Using a basic ItemsControl will do what you're looking for without the overhead of such a complex control. This approach is also very easy to customize by just changing the ItemTemplate.

    <ItemsControl ItemsSource="{Binding QuestionsToAnswer}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
    
                    <TextBlock Text="{Binding QuestionText}"/>
                    <TextBox Text="{Binding AnswerText}" Grid.Column="1"/>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    0 讨论(0)
  • 2021-01-20 16:52

    I agree with Scott that DataGrid is probably the way to go. Here are some decent turotials to get you started:
    http://www.c-sharpcorner.com/UploadFile/mahesh/WpfDGP109272009111405AM/WpfDGP1.aspx
    http://www.wpftutorial.net/DataGrid.html

    0 讨论(0)
提交回复
热议问题