locked
how create nested controls dynamically ?

    Question

  • Hi All,

    Am developing Windows 8 App.

    My requirement is Generate Nested Controls Dynamically.

    i.e.,

    1.Are you married? 

    if ans:yes

    1A.what is your spouse name?

    if ans:no

    2.How old are you?

    Am Able to create dynamic control.

    but am stuck in creating nested controls.

    Any Suggestion would be of great help.

    Thanks


    Arjun

    Wednesday, June 4, 2014 12:55 PM

All replies

  • Hi Arjun - I don't know what about this is "nested controls".  This seems really straightforward control-flow.  Can you explain exactly where you're encountering the problem?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, June 4, 2014 7:28 PM
    Moderator
  • Hi Matt,

    Thanks For your Response.

    I am facing problem in creating child question for a parent question.

    i.e., my code works fine if there is no sub question for a parent question .

    but if there is sub question

    i.e., 

    1) Are you a Minor? 

    Ans: NO

    here i should create a new question below the parent question

    11) how old are you?

    Ans:25

     if for the first question user answers "yes" in that case i should't show qn"11"

    i have to show below question directly

    2)what is your name?

    Ans:Arjun

    Any suggestion would be of great help

    Thanks


    Arjun

    Thursday, June 5, 2014 5:05 AM
  • I recommend that you place all of your questions on the XAML page and show/hide them dynamically:

     <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock FontSize="20">Are you married?</TextBlock>
                    <RadioButton Content="Yes" GroupName="Married" x:Name="MarriedCheckBoxYes" Checked="MarriedCheckBox_Checked"/>
                    <RadioButton Content="No" GroupName="Married" x:Name="MarriedCheckBoxNo" Checked="MarriedCheckBox_Checked"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Visibility="Collapsed" x:Name="SpouseNameQuestion">
                    <TextBlock FontSize="20">What is your spouse's name?</TextBlock>
                    <TextBox x:Name="SpouseName" Width="200" FontSize="20"/>
                </StackPanel>
    v        </StackPanel>
    
    
    private void MarriedCheckBox_Checked(object sender, RoutedEventArgs e)
            {
                if (MarriedCheckBoxYes.IsChecked == true) SpouseNameQuestion.Visibility = Windows.UI.Xaml.Visibility.Visible;
                else SpouseNameQuestion.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
    
            }


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, June 5, 2014 2:49 PM
    Moderator
  • Hi Matt,

    Thanks For your Response.

    Problem is i will get questions from database.

    as well as answers.

    i may have different number of question.

    its completely dynamic.

    so i need an approach from code behind only.

    Thanks


    Arjun

    Friday, June 6, 2014 5:39 AM
  • Hi,

    Would it be possible for you to post your database model, or at least the part regarding the questions?

    I'm thinking that you could have the hierarchical link between your questions in the database and then use this to bind it to the visibility property of any child panel you may have using a converter.

    I can be more specific once I see your db.

    Regards,

    • Proposed as answer by SisuHak Friday, June 6, 2014 11:49 AM
    Friday, June 6, 2014 10:16 AM
  • Hi SisuHak,

    Thanks For Your Response.

    Above is my DB Schema.

    Result Column Tells When We have to Show Child Questions. 

    Based on Result Column Answer i have generate Child Questions Dynamically.

    And these questions are coming from service.

    so i cannot hard code the controls in UI.

    Every control should be dynamic.

    So far i have achieved till getting only those question which has no child questions

    Thanks

    Arjun.M


    Arjun

    Friday, June 6, 2014 12:06 PM
  • Hi,

    Can you send me your data from the database in text format?

    Regards

    Friday, June 6, 2014 2:07 PM