如何在WPF中制作可重复的模板(How to make repeatable template in WPF)

我想制作像这张照片的WPF应用程序..

我想用这里的数据库结构制作数据输入应用程序(列)

A | B | C | D | ... | Z

我想要使​​可重复部分插入是否第2列和第3列是可选的。 所以它就像我的数据库中的水平行。

如何在WPF中使用数据绑定进行这样的结构布局? 我想让我的Textbox A将数据绑定到我的数据库中的文本框B将与B等绑定。

如何做到这一点的最佳方法......? 帮我..

I want make WPF application like this picture..

I want make data entry application with database structure like here (Columns)

A | B | C | D | ... | Z

And I want make repeatable section to insert whether Column 2 and Column 3 is optional. So it's like horizonal rows in my database.

How can I make structure layout like this in WPF with databinding? I want make my Textbox A will have data binding to A in my database Textbox B will be bind with B and etc..

How the best approach to doing this...? Help me..

最满意答案

看起来你只是想显示一个列表列表。

您可以将数据库表简化为以下内容:

Id | ColumnIndex | RowIndex | Value

您的查询可能如下所示:

GroupedValues = table.GroupBy(x => x.ColumnIndex);

然后你可以使用ItemsControl,将ItemsPanel设置为水平方向的StackPanel,将ItemTemplate设置为标准(垂直)ItemsControl,如下所示:

<ItemsControl ItemsSource="{Binding GroupedValues}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate&t; </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Value}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

此代码未经过测试,但希望它能为您提供这个想法。

It looks like you are just trying to show a list of lists.

You could simplify your database table to something like this:

Id | ColumnIndex | RowIndex | Value

Your query could look like this:

GroupedValues = table.GroupBy(x => x.ColumnIndex);

Then you can use an ItemsControl with ItemsPanel set to a horizontally oriented StackPanel and the ItemTemplate set to a standard (vertical) ItemsControl, like this:

<ItemsControl ItemsSource="{Binding GroupedValues}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Value}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

This code is not tested but hopefully it gives you the idea.

如何在WPF中制作可重复的模板(How to make repeatable template in WPF)

我想制作像这张照片的WPF应用程序..

我想用这里的数据库结构制作数据输入应用程序(列)

A | B | C | D | ... | Z

我想要使​​可重复部分插入是否第2列和第3列是可选的。 所以它就像我的数据库中的水平行。

如何在WPF中使用数据绑定进行这样的结构布局? 我想让我的Textbox A将数据绑定到我的数据库中的文本框B将与B等绑定。

如何做到这一点的最佳方法......? 帮我..

I want make WPF application like this picture..

I want make data entry application with database structure like here (Columns)

A | B | C | D | ... | Z

And I want make repeatable section to insert whether Column 2 and Column 3 is optional. So it's like horizonal rows in my database.

How can I make structure layout like this in WPF with databinding? I want make my Textbox A will have data binding to A in my database Textbox B will be bind with B and etc..

How the best approach to doing this...? Help me..

最满意答案

看起来你只是想显示一个列表列表。

您可以将数据库表简化为以下内容:

Id | ColumnIndex | RowIndex | Value

您的查询可能如下所示:

GroupedValues = table.GroupBy(x => x.ColumnIndex);

然后你可以使用ItemsControl,将ItemsPanel设置为水平方向的StackPanel,将ItemTemplate设置为标准(垂直)ItemsControl,如下所示:

<ItemsControl ItemsSource="{Binding GroupedValues}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate&t; </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Value}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

此代码未经过测试,但希望它能为您提供这个想法。

It looks like you are just trying to show a list of lists.

You could simplify your database table to something like this:

Id | ColumnIndex | RowIndex | Value

Your query could look like this:

GroupedValues = table.GroupBy(x => x.ColumnIndex);

Then you can use an ItemsControl with ItemsPanel set to a horizontally oriented StackPanel and the ItemTemplate set to a standard (vertical) ItemsControl, like this:

<ItemsControl ItemsSource="{Binding GroupedValues}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Value}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

This code is not tested but hopefully it gives you the idea.