Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:15:13+00:00 2026-06-02T13:15:13+00:00

If I have this structure: public class Parent { public string Name{get; set;} public

  • 0

If I have this structure:

public class Parent
{
  public string Name{get; set;}
  public List<Child> Childs {get; set;}
}

public class Child
{
  public string Name{get; set;}
  public string Value{get; set;}
  public enum ValueType {get; set;}
}

public enum ValueType
{
    Int,
    Boolean,
    String
};

public class ParentFactory
{
   public List<Parent> Parents {get; set;}

   public ParentFactory()
   {
      Child child1 = new Child() {Name="Filter1", Value="1", ValueType=ValueType.String};
      Child child2 = new Child() {Name="isExecuted", Value="true", ValueType=ValueType.Boolean};
      Child child3 = new Child() {Name="Width", Value="10", ValueType=ValueType.Int};

      Parent parent1 = new Parent(){Name="Adam", Childs = new List<Child>(){child1, child2}};
      Parent parent2 = new Parent(){Name="Kevin", Childs = new List<Child>(){child3}};

      Parents = new List<Parent>(){parent1, parent2};
   }
}

I want to bind the object: ParentFactory parentFactory = new ParentFactory() to ItemsControl:

<DockPanel>
    <ItemsControl ItemsSource="{Binding Parents}">
    </ItemsControl>
</DockPanel>

 <Window.Resources>
     <DataTemplate DataType="{x:Type Parent}">
         <StackPanel Margin="2,2,2,1">
              <Expander Header="{Binding Name}">
                  <ItemsControl ItemsSource="{Binding Childs}" />
              </Expander>
         </StackPanel>
     </DataTemplate>
        <DataTemplate DataType="{x:Type Child}">
            <StackPanel>
                    <TextBox Grid.Column="0" Text="{Binding Name}" />
                    <TextBox Grid.Column="1" Text="{Binding Value}"/>
                    <TextBox Grid.Column="2" Text="{Binding ValueType}"/>
            </StackPanel>
        </DataTemplate>
 </Window.Resources>

In the Stackpanel, there are one control: TextBox. However, I want it to be more dynamic: if the ValueType is a Boolean then use a Checkbox and else use a Textbox for the: <TextBox Grid.Column="1" Text="{Binding Value}"/>.

Is this possible, and if so, how can I achieve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:15:15+00:00Added an answer on June 2, 2026 at 1:15 pm

    I think the easiest way to do it is to have both of them in your panel and define two new boolean properties that will control their Visibility through a Boolean To Visibility ValueConverter.

    public bool IsValueTypeBoolean
    {
        get
        {
             ...Conditions that will return true for CheckBox.
        }
    }
    
    public bool IsValueTypeOther
    {
        get
        {
             return !this.IsValueBoolean;
        }
    }
    
    <TextBox Grid.Column="2" Visibility="{Binding IsValueTypeOther, Converter={StaticResource visibilityConverter}}"/> 
    <CheckBox Grid.Column="2" Visibility="{Binding IsValueTypeBoolean, Converter={StaticResource visibilityConverter}}"/> 
    

    Boolean To VisibilityConverter

    [ValueConversion(typeof(bool), typeof(Visibility))]
    public class BooleanToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool myValue = (bool)value;
    
            if (myValue)
                return Visibility.Visible;
            else
                return Visibility.Collapsed;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Add this as a resource to your XAML:

     <local:BooleanToVisibilityConverter x:Key="visibilityConverter"></local:VisibilityConverter>
    

    I hope there are no typos…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have this structure: public class Parent { public string Name{get; set;} public
I have this simple structure: 1 parent, and two different childs. public class Parent{}
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
Let's say I have this simple structure class FooDefinition { public FooDefinition Parent {
I have following structure: class Employee { public long Id { get; set; }
I have this structure of classes: public class L3Message { public int Number {
I have a structure similar to this: class OuterClass{ AnimatorListener sth; public OuterClass(){ sth
I have this structure on form, <input type=test value= id=username /> <span class=input-value>John Smith</span>
Suppose i have this structure of elements: <div class=parent> <div class=something1> <div class=something2> <div
I have this HTML structure (excerpt): <td> <select id=test1 class=pub_chooser> <option value=99>All Publications</option> <option

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.