Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF:由a对齐的动态表单<;网格>;_Wpf - Fatal编程技术网

WPF:由a对齐的动态表单<;网格>;

WPF:由a对齐的动态表单<;网格>;,wpf,Wpf,我正在构建一个GUI,根据模式允许的值编辑各种XML配置文件。我需要一种方法来显示左栏中每个字段的标签,同时在右栏中显示编辑该字段的控件。如果这个字段列表不是动态的,我只需要将它们显示在一个包含两列的网格中。但对于动态字段列表来说,这似乎并不容易 下面的示例显示了我想要做的事情,但是因为DataTemplate只能包含一个子项,所以这种方法不起作用。有谁知道一个好的解决方法可以使这个动态表单布局正确 (为了简化示例,我使用的是统一网格。我可能更喜欢在ControlTemplate中删除网格的方法

我正在构建一个GUI,根据模式允许的值编辑各种XML配置文件。我需要一种方法来显示左栏中每个字段的标签,同时在右栏中显示编辑该字段的控件。如果这个字段列表不是动态的,我只需要将它们显示在一个包含两列的网格中。但对于动态字段列表来说,这似乎并不容易

下面的示例显示了我想要做的事情,但是因为DataTemplate只能包含一个子项,所以这种方法不起作用。有谁知道一个好的解决方法可以使这个动态表单布局正确

(为了简化示例,我使用的是统一网格。我可能更喜欢在ControlTemplate中删除网格的方法(这样您就可以定义列/行)-但是,我认为这种方法可以理解这一点)



谢谢

您可以用DataTemplate替换面板中需要的内容。看看这个:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:System="clr-namespace:System;assembly=mscorlib" >
  <Grid>  
    <ItemsControl>
      <ItemsControl.ItemTemplate>
        <DataTemplate>
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="FieldName" Grid.Column="0"  HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0, 0, 14, 0" />
            <TextBox Text="FieldValue" Grid.Column="1" />
          </Grid>
        </DataTemplate>
      </ItemsControl.ItemTemplate>
     <System:String>Hello</System:String>
     <System:String>World</System:String>
    </ItemsControl>
  </Grid>
</Page>

你好
世界
<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:System="clr-namespace:System;assembly=mscorlib" >
  <Grid>  
    <ItemsControl>
      <ItemsControl.ItemTemplate>
        <DataTemplate>
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="FieldName" Grid.Column="0"  HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0, 0, 14, 0" />
            <TextBox Text="FieldValue" Grid.Column="1" />
          </Grid>
        </DataTemplate>
      </ItemsControl.ItemTemplate>
     <System:String>Hello</System:String>
     <System:String>World</System:String>
    </ItemsControl>
  </Grid>
</Page>