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

  • Home
  • SEARCH
  • 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 8926625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:01:03+00:00 2026-06-15T08:01:03+00:00

My small objective is to implement a dynamic on-the-go generation of controls and associate

  • 0

My small objective is to implement a dynamic on-the-go generation of controls and associate their respective properties, such as Visibility and IsEnabled.

The controls must be inserted into the StackPanel. And based on some conditions, the children nodes properties would change. I’ve used the following nasted StackPanel structure:

  1. The Parent StackPanel with Vertical orientation of Children (collection of Labels ad input Fields to simulate a form)
  2. The Child node StackPanel with Horizontal orientation of Children (Label and an input field)

The main idea is that there is only one input field per each label: Date Picker, Combo, Text or any other. As result, I created a Label and a Grid with multiple Controls. I manipulate Visibility and IsEnabled properties of the input controls via Converters.

Here is the question: is it possible to implement all these by other means (more efficient/aesthetic)? Constructive criticism and suggestions are more than welcome 🙂

Thank you in advance.

XAML:

<StackPanel Grid.Row="1" Orientation="Vertical">
    <ItemsControl ItemsSource="{Binding DataClass}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" Margin="0, 5, 0, 0" >
                    <Label Content="{Binding KeyName}" Width="150"/>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="190"/>
                        </Grid.ColumnDefinitions>
                        <DatePicker Text="{Binding Value}"
                            Visibility="{Binding Type, Converter={StaticResource TypeVisiblity}, ConverterParameter='DateTime'}"
                            IsEnabled="{Binding RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource VisibilityEnabled}}"/>
                        <ComboBox Text="{Binding Value}" 
                            Visibility="{Binding Type, Converter={StaticResource TypeVisiblity}, ConverterParameter='Lookup'}"
                            IsEnabled="{Binding RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource VisibilityEnabled}}"/>
                        <TextBox Text="{Binding Value}" 
                            Visibility="{Binding Type, Converter={StaticResource TypeVisiblity}, ConverterParameter='Number'}"
                            IsEnabled="{Binding RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource VisibilityEnabled}}"/>
                        <TextBox Text="{Binding Value}" 
                            Visibility="{Binding Type, Converter={StaticResource TypeVisiblity}, ConverterParameter='Text'}"
                            IsEnabled="{Binding RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource VisibilityEnabled}}"/>
                    </Grid>
                </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>

Visibility Converter:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        bool isMatched;
        string type,
               controlType;

        // Safe Convert.
        type = System.Convert.ToString(value);
        controlType = System.Convert.ToString(parameter);

        if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(controlType))
        {
            return Visibility.Hidden;
        }

        // Check matching.
        isMatched = string.Equals(type, controlType, StringComparison.CurrentCultureIgnoreCase);

        return isMatched ? Visibility.Visible : Visibility.Hidden;
    }

IsEnabled Converter:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    Control control;

    control = value as Control;

    if (control == null)
    {
        return false;
    }

    return control.Visibility == Visibility.Visible;
}
  • 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-15T08:01:04+00:00Added an answer on June 15, 2026 at 8:01 am

    I would use a ContentControl and set the ContentTemplate in a style

    <ContentControl>
        <ContentControl.Style>
            <Style TargetType="{x:Type ContentControl}">
                <!-- Default Template -->
                <Setter Property="ContentTemplate" 
                        Value="{DynamicResource TextBoxTemplate}" />
    
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Type}" Value="DateTime">
                        <Setter Property="ContentTemplate" 
                                Value="{DynamicResource DateTimeTemplate}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Type}" Value="Lookup">
                        <Setter Property="ContentTemplate" 
                                  Value="{DynamicResource ComboBoxTemplate}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
    </ContentControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello I have a small question in objective-C memory management. I know that if
I'm new to objective C and currently working on a small project. I have
I am learning objective c and am making some small programs. For my current
I'm new to objective-c and at the moment developing a small application. I have
Which would be a more appropriate repository to host a small, XCode, Objective-C based
Objective Have a small magnifying glass icon that appears in the top right corner
I was implementing a small cmd calculator in Objective-C for OOP practice. I was
I just started to learn Objective c. Now i want a under title (small
In Objective C, is there a one-liner or something small to remove (shorten by
I am porting a small function from C# to Objective-C (for the iPhone), and

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.