0

私には複数の子供を持つ母親がいます。各子にはすでに名前が割り当てられており、ユーザーが値を入力する必要があります。

コードを使用して、子ごとに TextBlock と TextBox を使用して StackPanel を生成しようとしています。子の数は不明であるため、各 StackPanel を作成し、それらを Border コントロールに追加される「お母さん」StackPanel にループする必要があります。コードを実行すると、ループは正常に実行されますが、ディスプレイには何も表示されません。

コードは次のとおりです。

var momStackPanel = new StackPanel() { Orientation = Windows.UI.Xaml.Controls.Orientation.Vertical};
foreach (ChildItem item in ChildList)
{
    var childItemSP = new StackPanel();childItemSP.Orientation = Orientation.Horizontal;
    TextBlock nameTB = new TextBlock();
    name.Text = item.Name;
    childItemSP.Children.Add(nameTB);
    TextBox valueTB = new TextBox();
    valueTB .Text = item.Value;
    childItemSP.Children.Add(valueTB);
}
BorderSection.Child = momStackPanel;
BorderSection.Visibility = Windows.UI.Xaml.Visibility.Visible;

XAML は次のとおりです。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition  Height="Auto" />
        <RowDefinition  Height="Auto"/>
        <RowDefinition  Height="Auto"/>
        <RowDefinition  Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <TextBlock  x:Name="t4"  Text="t4"  Grid.Row="0"/>
    <Border Grid.Row="1"  HorizontalAlignment="Stretch">
                <StackPanel >
                    <TextBlock x:Name="r1" Text="{Binding r1}"  HorizontalAlignment="Center" />
                    <TextBlock x:Name="r2" Text="r2" Foreground="DarkGray"/>
                </StackPanel>               
    </Border>
    <Border x:Name="BorderSection" Grid.Row="2">            
    </Border>
    <StackPanel x:Name="CommentPanel" Orientation="Vertical" Grid.Row="3" Margin="6,6,6,6">
        <TextBox x:Name="Comment" Text="" MinHeight="100"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal" >
        <Button x:Name="Submit" Content="Submit" Click="Submit_Click_1"/>
        <Button x:Name="Cancel" Content="Cancel" Click="Cancel_Click_1"/>
    </StackPanel>
</Grid>

これに対処する方法はありますか?

4

1 に答える 1