0

ラベルとコンボ ボックスを含むグリッドの自動生成を行うにはどうすればよいですか。私が望むのは、ユーザーがコンボボックス1でオプションを選択すると、メソッドが別のグリッド(コンボボックス2を含む)を自動生成することです。

以下は私が現在持っているコードで、現在のコンボボックスでIsSelectedが呼び出されたら、次のグリッドを表示するイベント駆動型メソッドを作成したいと思っています。

 <Grid x:Name="comp1" Margin="0,84,230,345">
            <Label Content="Test Component 1:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,4,0,0"/>
        </Grid>
        <Grid x:Name="comp2" Margin="0,127,230,302" Visibility="Hidden">
            <Label Content="Test Component 2:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,4,0,0"/>
        </Grid>
        <Grid x:Name="comp3" Margin="0,166,230,262" Visibility="Hidden">
            <Label Content="Test Component 3:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB3" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,5,0,0"/>
        </Grid>
        <Grid x:Name="comp4" Margin="0,205,230,222" Visibility="Hidden">
            <Label Content="Test Component 4:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB4" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,6,0,0"/>
        </Grid>
        <Grid x:Name="comp5" Margin="0,245,230,182" Visibility="Hidden">
            <Label Content="Test Component 5:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB5" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,6,0,0"/>
        </Grid>
        <Grid x:Name="comp6" Margin="0,281,230,145" Visibility="Hidden">
            <Label Content="Test Component 6:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,3,0,0"/>
            <ComboBox x:Name="testCompCB6" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,10,0,-3"/>
        </Grid>
        <Grid x:Name="comp7" Margin="0,328,230,100" Visibility="Hidden">
            <Label Content="Test Component 7:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB7" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,5,0,0"/>
        </Grid>
        <Grid x:Name="comp8" Margin="0,370,230,59" Visibility="Hidden">
            <Label Content="Test Component 8:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB8" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,3,0,0"/>
        </Grid>
        <Grid x:Name="comp9" Margin="0,406,230,15" Visibility="Hidden">
            <Label Content="Test Component 9:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
            <ComboBox x:Name="testCompCB9" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Margin="134,12,0,0"/>
        </Grid>
4

1 に答える 1

0

これに興味のある方、こんにちは。手続き型コーディングの単純な方法に従って解決しました。

xaml の場合:

<StackPanel x:Name="testCompList" HorizontalAlignment="Left" Height="274" Margin="10,92,0,0" VerticalAlignment="Top" Width="361">
            <Canvas x:Name="comp1" Margin="0,0,8,0" Height="26">
                <Label Content="Test Component 1:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp2" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 2:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp3" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 3:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp3" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp4" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 4:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp4" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp5" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 5:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp5" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp6" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 6:" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Top="3"/>
                <ComboBox x:Name="testComp6" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp7" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 7:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp7" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp8" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 8:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp8" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5" DropDownClosed="addNewRow"/>
            </Canvas>
            <Canvas x:Name="comp9" Margin="0,0,8,0" Height="26" Visibility="Hidden">
                <Label Content="Test Component 9:" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                <ComboBox x:Name="testComp9" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" IsEditable="True" Tag="Test Component" Canvas.Left="134" Canvas.Top="5"/>
            </Canvas>
        </StackPanel>

コード ビハインドの場合:

int i = 1;        
private void addNewRow(object sender, EventArgs e) //all will invoke this generic     method to display the visibility of the next
    {
        ComboBox selectedTest = (ComboBox)sender;
        Canvas thisRow = (Canvas)selectedTest.Parent;
        int index =Int32.Parse(thisRow.Name.Substring(thisRow.Name.Length-1, 1));
        if (thisRow is Canvas && index==i) //needs to ensure that only the previous canvas can invoke the next canvas once selection is done
        {
            i++;
            Canvas newRow = (Canvas)this.FindName("comp" + i);
            newRow.Visibility = Visibility.Visible;
            //add the test Component to a data structure like a list or something

        }

    }
于 2013-04-05T03:49:52.670 に答える