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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:35:44+00:00 2026-06-18T00:35:44+00:00

Let’s say there is a forward linked list: public class A { public B

  • 0

Let’s say there is a forward linked list:

public class A
{
    public B Next { get; set; }

    public String Value { get; set; }

    public A(string value, B next)
    {
        this.Next = next;
        this.Value = value;
    }
}

public class B
{
    public A Next { get; set; }
    public int Value { get; set; }

    public B(int value, A next)
    {
        this.Next = next;
        this.Value = value;
    }
}

public partial class MyWindow : Window
{

    public A My_List{ get; set; }

    public MyWindow()
    {
        Program program = new Program();

        this.My_List = new A("value1", new B(1, new A("Value2", new B(2, new A("value3", new B(3, null))))));

        this.DataContext = this;
        InitializeComponent();
    }
}

How can I show the *My_List* in Wpf?
I tried:

<StackPanel>
    <StackPanel.Resources>
        <DataTemplate DataType="{x:Type WpfApplication2:A}" x:Key="A_Template">
            <StackPanel Orientation="Horizontal">
                <Label Content="{Binding Path=Value}" />
                <Label Content="---" />
                <Label Content="{Binding Path=Next.Value}" />
                <ItemsControl ItemsSource="{Binding Path=Next.Next}" ItemTemplate="{DynamicResource A_Template}">

                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

                </ItemsControl>
            </StackPanel>
        </DataTemplate>
    </StackPanel.Resources>

    <ItemsControl   ItemsSource="{Binding Path=My_List}"
                    ItemTemplate="{StaticResource A_Template}">

        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</StackPanel>

But it does not work, I think it is because *My_List* has to be a actual list and not the first element.

Edit: There is just an empty window, no output, no compiler error an no runtime exception.

  • 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-18T00:35:45+00:00Added an answer on June 18, 2026 at 12:35 am

    How can I show the *My_List* in Wpf?

    If you want to use A as an ItemsSource for ItemsControl, then you have to implement IEnumerable in A like this:

    public class A : IEnumerable
    {
        public B Next { get; set; }
    
        public String Value { get; set; }
    
        public A(string value, B next)
        {
            this.Next = next;
            this.Value = value;
        }
    
        #region IEnumerable Members
    
        private class AEnumerator : IEnumerator
        {
            private readonly A head;
    
            public AEnumerator(A head)
            {
                this.head = head;
            }
    
            #region IEnumerator Members
    
            public object Current { get; private set; }
    
            public bool MoveNext()
            {
                if (Current == null)
                {
                    Current = head;
                }
                else
                {
                    if (Current.GetType() == typeof(A))
                    {
                        Current = ((A)Current).Next;
                    }
                    else
                    {
                        Current = ((B)Current).Next;
                    }
                }
    
                return Current != null;
            }
    
            public void Reset()
            {
                throw new NotImplementedException();
            }
    
            #endregion
        }
    
        public IEnumerator GetEnumerator()
        {
            return new AEnumerator(this);
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have classes like this: public class Parent { public int
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have pseudocode like this: main() { BOOL b = get_bool_from_environment(); //get
Let's say we have this simple class: class example { bool m_isCanceled; example() :
Let's say I have an abstract parent class called shape, and that there are
Let's say I got this string: $str = alemylaife; (I know it's misspelled, all
Let's say there is a list of List<UInt32> Thus, : 12|12 23|33 33|22 11|22
Let say you have an XML like this: <?xml version=1.0 encoding=utf-8?> <Class HashCode=307960707> <Person>
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object

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.