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 8032685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:27:35+00:00 2026-06-05T01:27:35+00:00

I am beginner in wpf, and I have a problem with stackpanel binding. I

  • 0

I am beginner in wpf, and I have a problem with stackpanel binding.
I have to dynamically generate labels, and add it to stackpanel.
I had following code in .cs file:

    public DataImport()
    {
        labels.Add(new StringObject { Value = "tes" });
        labels.Add(new StringObject { Value = "tes2" });
        labels.Add(new StringObject { Value = "tes3" });
    }
    private ObservableCollection<StringObject> labels = new ObservableCollection<StringObject>();

    public ObservableCollection<StringObject> Labels
    {
        get { return labels; }
        private set
        {
            if (value == labels) return;
            labels = value;
            OnPropertyChanged("Labels");
        }
    }
    public class StringObject
    {
        public string Value { get; set; }
    }

Next in xaml I have:

<ItemsControl ItemsSource="{Binding Path=Labels}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Grid.Row="1" Height="237" HorizontalAlignment="Center" VerticalAlignment="Top" Width="186" FlowDirection="LeftToRight">
                <Label Content="{Binding Path=Value}"/>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

The real problem is that in xaml window I see only the first element from the labels object.
Can u tell me what i did wrong ?

PS: my class DataImport of course inherits INotifyPropertyChanged

  • 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-05T01:27:37+00:00Added an answer on June 5, 2026 at 1:27 am

    The ItemTemplate is per item. So just specify a label.

    <ItemsControl ItemsSource="{Binding Path=Labels}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Label Content="{Binding Path=Value}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code to be implemented into my xaml file. <ItemsControl ItemsSource={Binding
I am beginner on WPF and need your help. Problem: I have 4 buttons
I am a beginner at using WPF. I have wrote some xaml code in
I am a beginner to WPF . I have a data grid for showing
Absolute beginner question: I have a template file index.html that looks like this: ...
I'm a complete beginner in WPF and have an app that uses StoryBoard to
I have a datagrid in a WPF populated from a csv file. This is
I have a small-scale WPF application using VB.net as the code behind and I
Beginner to assembly programming for x86. I have a simple asm file which I
I'm a relative beginner with WPF so please bear with me. I have a

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.