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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:32:25+00:00 2026-05-20T06:32:25+00:00

I am developing window phone 7 application. I am new to the window phone

  • 0

I am developing window phone 7 application. I am new to the window phone 7 application. I have the following listbox control in my application

<ListBox Margin="0,355,70,205" Name="WeekSummaryListBox" DataContext="{Binding}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Amount}" Foreground="Orange"></TextBlock>
                <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Currency}" Foreground="Orange"></TextBlock>                            
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>

    <ListBox.Template>
        <ControlTemplate>
            <ScrollViewer HorizontalScrollBarVisibility="Visible">
                <ItemsPresenter />
            </ScrollViewer>
        </ControlTemplate>
    </ListBox.Template>
</ListBox>

In the above listbox control items are displayed vertically. I want to display the items in a listbox control horizonatlly. So I am using the following code.

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>

but when I put the two textblock inside stackpanel it gives error. For this I am using the following code

<StackPanel Orientation="Horizontal">
    <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Amount}" Foreground="Orange"></TextBlock>
    <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Currency}" Foreground="Orange"></TextBlock>                            
</StackPanel>

I am trying for the following code. In the following code I am getting error

<ListBox Margin="0,355,70,205" Name="WeekSummaryListBox" DataContext="{Binding}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Amount}" Foreground="Orange"></TextBlock>
                <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Currency}" Foreground="Orange"></TextBlock>
            </StackPanel>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.Template>
        <ControlTemplate>
            <ScrollViewer HorizontalScrollBarVisibility="Visible">
                <ItemsPresenter />
            </ScrollViewer>
        </ControlTemplate>
    </ListBox.Template>
</ListBox>

I am getting the error “Cannot explicitly modify children collection of Panel used as ItemsPanel for ItemsControl.ItemsControl geneartes child elements for Panel”

I am using the following function to display the data in the ListBox:

public void WeekSumValue(int TransactionType_ID)
{
    UserInterfaceManager UserInterfaceManagerObj = new UserInterfaceManager();
    List<UserInterfaceManager.TotalSummary> WeekSummary = new List<UserInterfaceManager.TotalSummary>();           
    ObservableCollection<AmountCurrency> WeekIncomeSumCollection = new ObservableCollection<AmountCurrency>();

    WeekSummary = UserInterfaceManagerObj.LoadWeekSum(SelectedButtonName, TransactionType_ID, selectedDate);

    foreach (UserInterfaceManager.TotalSummary vWeekSummary in WeekSummary)
    {
        WeekIncomeSumCollection.Add(new AmountCurrency(vWeekSummary.Amount, vWeekSummary.Currency));
    }

    if (WeekIncomeSumCollection.Count != 0 && SummaryCombobox.SelectedIndex == 0)
    {
        WeekSummaryListBox.ItemsSource = WeekIncomeSumCollection;
    }
    else if (WeekIncomeSumCollection.Count != 0 && SummaryCombobox.SelectedIndex == 2)
    {
        MonthSummaryListBox.ItemsSource = WeekIncomeSumCollection;
    }
    else
    {
        ObservableCollection<TextBlock> NoRecordsCollection = new ObservableCollection<TextBlock>();
        TextBlock NoRecordsTextBlock = new TextBlock();
        NoRecordsTextBlock.Text = "No record found";
        NoRecordsTextBlock.FontSize = 25;
        NoRecordsTextBlock.Foreground = new SolidColorBrush(Colors.Gray);
        NoRecordsCollection.Add(NoRecordsTextBlock);

        if (SummaryCombobox.SelectedIndex == 0)
            WeekSummaryListBox.ItemsSource = NoRecordsCollection;

        if (SummaryCombobox.SelectedIndex == 2)
            MonthSummaryListBox.ItemsSource = NoRecordsCollection;
    }
}

In the above function data is coming dynamically. There can be two, three or more records also there can be no record. I am binding this dynamic data to the textblocks which are inside the listbox

I am using the following class used in the above code

public class AmountCurrency
{
    public int Amount { get; set; }
    public String Currency { get; set; }

    public AmountCurrency(int Amount, String Currency)
    {
        this.Amount = Amount;
        this.Currency = Currency;
    }
}

How should I put the above two textbock inside the listbox which will display the items horizonatlly ? Can you please provide me any code or link through which I can resolve the above issue ? If I am doing anything wrong then please guide me.

  • 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-05-20T06:32:25+00:00Added an answer on May 20, 2026 at 6:32 am

    It looks to me like you’ve got the two text blocks inside the wrong part of the template.

    These two text blocks should be in the ListBox.ItemTemplate, not in the ListBox.ItemsPanelTemplate:

    <ListBox ItemsSource="{Binding Items}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"></StackPanel>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="0,0,0,17" Width="300" Orientation="Horizontal">
                    <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Amount}" Foreground="Orange"></TextBlock>
                    <TextBlock TextWrapping="Wrap" Width="150" Text="{Binding Currency}" Foreground="Orange"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    If you want to understand how this control works, then start from a working “basic” control which shows items and then look at adding the ItemsPanelTemplate to that working sample.

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

Sidebar

Related Questions

I am developing window phone 7 application. I have a listbox in my application.
I am developing window phone 7 application. I am new to the window phone
I am developing window phone 7 application. I am new to the window phone
I am developing window phone 7 application. I am new to the Window Phone
I am developing window phone 7 application. I am new to the window phone
I am developing the window phone 7 application. I am new to the window
I am developing window phone 7 application in C#. I am new to the
I am developing window phone 7 application. I am new to the window phone
I'm developing a Windows Phone 7.1 application. I have the following folders structure: -
I'm developing a Windows Phome application. I have the following ListBox on a page:

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.