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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:16:19+00:00 2026-05-26T00:16:19+00:00

I am a beginner with WPF. I fear this may sound like a silly

  • 0

I am a beginner with WPF. I fear this may sound like a silly question.

I have a listbox with two columns. Each listbox item contains a horizontal stacked panel which in turn contains textblocks.

The listbox is empty, with each listbox item being added by the end-user through a couple of textboxes placed elsewhere. The first column accepts strings, and the second column accepts only percentages.

(I have attached a relevant portion of the event sub where a user is adding new rows.)

Private Sub btnAddItem_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnAddSplit.Click

'...

Dim ListBoxItemName As New TextBlock
ListBoxItemName.Text = Name.Text
ListBoxItemName.Width = 170

Dim ListBoxItemValue As New TextBlock
ListBoxItemValue.Text = SplitValue.Text
ListBoxItemValue.Width = 70

Dim ListBoxStackPanel As New StackPanel
ListBoxStackPanel.Orientation = Orientation.Horizontal
ListBoxStackPanel.Children.Add(ListBoxItemName)
ListBoxStackPanel.Children.Add(ListBoxItemValue)

Dim NewEntry As New ListBoxItem
NewEntry.Content = ListBoxStackPanel

MyListBox.Items.Add(NewEntry)

'...

End Sub 

I would like to be able to check every time the above event is fired that the column of percentages does not exceed 100%. I have a couple of labels below the listbox itself where I would like to show the running total and the remainder.

My questions are:

1) How can I loop through the second column of percentages to show the running total and remainder?

2) Is there something more suitable than a ListBox that could make this easier?

I would appreciate any sort of guidance towards a solution on this, regardless of whether it is in VB or C#. Thank you very much.

  • 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-26T00:16:19+00:00Added an answer on May 26, 2026 at 12:16 am

    Based on your code sample, it appears as if you’re going through the same issues I went through when I first started with WPF. It’s difficult to let go of that codebehind mentality and to embrace databinding, but I think you should give it a try. You will probably find that it’s worth it.

    Ultimately, I think your best bet would be to bind some collection of objects to the listbox and then iterate through this collection, like…

    <ListBox ItemsSource="{Binding StringPercentageCollection}" ... /> And bind your columns, or your textblocks, or whatever your layout is, to the public properties of “YourStringPercentageObject”.

    And then “StringPercentageCollection” might be an ObservableCollection (or some other collection) of YourStringPercentageObject in the data context. Then you’d be able to iterate through the observable collection normally.

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

Sidebar

Related Questions

I am a beginner to WPF . I have a data grid for showing
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Beginner question: I have a dictionary where the values are lists of (a variable
I am beginner on WPF and need your help. Problem: I have 4 buttons
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 came from another question to this one: How can one start with
Okay here is a softball beginner WPF question. By default the background of the
I'm a beginner in WPF and currently working on my first app. For this
First to tell you i am really new to WPF I have some Question

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.