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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:31:07+00:00 2026-06-11T12:31:07+00:00

Have got myself very confused on this one – apologies if the answer is

  • 0

Have got myself very confused on this one – apologies if the answer is really obvious but I am quite new to programming.

I have a user control set up as a view which is loaded into a content control within my main view. The datacontext for the usercontrol (Called SetView) is set in the MainView. I can happily bind to the SetView to UserControlVM (called SetVM).

In the SetVM I load in an ObservableCollection of a class I have created:

    public class WeightSet : Weights
{


    public string BodyArea { get; set; }
    public string ExerciseType { get; set; }
    public int SetNumber { get; set; }
    public static ObservableCollection<int> Reps { get; set; }


    #region Constructor


    //This is the main constructor
    public WeightSet(string bodyarea, string exerciseType, int setNumber)
    {
        BodyArea = bodyarea;
        ExerciseType = exerciseType;
        SetNumber = setNumber;
        Reps = new ObservableCollection<int>();
        AddReps();

    }

    #endregion Constructor

    #region Methods

    public void AddReps()
    {
        for (int i = 1; i < 100; i++)
        {
            Reps.Add(i);
        }
    }
    #endregion Methods

My SetView then has a ListView whose ItemsSource is

public ObservableCollection<WeightSet> Sets

Here is the xaml for the ListView:

<UserControl x:Class="CalendarTest.SetView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:forcombo="clr-namespace:CalendarTest.Model.Repository.Local_Data"
         xmlns:VM="clr-namespace:CalendarTest.ViewModel"
         mc:Ignorable="d" 
         d:DesignHeight="165" d:DesignWidth="300">
<Grid >
    <StackPanel>
    <StackPanel Orientation="Horizontal">
        <Label Content="{Binding CurrentExercise}" Width="100" Height="40"></Label>
        <Label Content="{Binding BodyArea}" Width="100" Height="40"></Label>

    </StackPanel>
        <ListView ItemsSource="{Binding Sets}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Set Number" DisplayMemberBinding="{Binding Path=SetNumber}" Width="100"></GridViewColumn>
                    <GridViewColumn Header="Select Reps" Width="120">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox Width="100" ItemsSource="{Binding Source={x:Static forcombo:WeightSet.Reps }}" ></ComboBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>

                    </GridViewColumn>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Reps}"></GridViewColumn>
                </GridView>
            </ListView.View>


        </ListView>
    </StackPanel>

</Grid>

When I load SetView I have my list of set numbers and a combobox with the staticlist. Here is a shot:

enter image description here

I cant seem to bind the selecteditem for the comboBox back to my ViewModel. Is there a way to set the selected item in the WeightSet Class? I need to be able to save the selected number?

I understand that I cant just bind to a property as the number of ComboBoxs will be decided by user? Any tips or corrections to my current design would be much appreciated

  • 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-11T12:31:08+00:00Added an answer on June 11, 2026 at 12:31 pm

    You can bind the SelectedItem property on your combobox, and add a dependencyproperty in your WeightSet class

    xaml:

    <ComboBox ItemsSource="{Binding Source={x:Static forcombo:WeightSet.Reps }}"
              SelectedItem="{Binding SelectedItem}" />
    

    and the property

    public static readonly DependencyProperty SelectedItemProperty =
        DependencyProperty.Register("SelectedItem", typeof (int), typeof (WeightSet), new PropertyMetadata(default(int)));
    
    public int SelectedItem {
        get { return (int) GetValue(SelectedItemProperty); }
        set { SetValue(SelectedItemProperty, value); }
    }
    

    Then SelectedItem in your Sets instances will be updated when a value is selected in the combobox.

    • 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 and got myself confused: I have a query that
I have got myself really tied up with a web user control and the
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have got two pages. example.com/php.com and example.com. I use this function to set
I have recently installed Reshaper....this is very good and helpful however it has changed
This seems like a very simple question, but I've only found complicated answers. I've
This is a very trivial problem but I can't seem to find a way
As im quite new to obj-C but on the other hand a common user
Ok guys I know this question has been asked before but I am very
I've got a very simple program written in C#, but the loop never exits

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.