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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:16:18+00:00 2026-06-10T08:16:18+00:00

This has me stumped – hopefully someone can point out an obvious error. I

  • 0

This has me stumped – hopefully someone can point out an obvious error. I have a user control that I am adding to a grid in the MainView of my program. Main view is bound to MainViewModel and the usercontrol is bound to CardioVM.

I have used a test label to check that the routing of the user control is correct and all work ok. I have a class named Cardio which has a property of

    List<string> exercises 

I am trying to pass the strings in

Cardio.List<string> exercises 

to a

List<string> CardioList 

in my CardioVM. When debugging

List<string> CardioList 

is getting populated with items from

Cardio.List<string> exercises

but my ComboBox is not displaying the items on screen. Here is xaml for my UserControl and :

<UserControl x:Class="CalendarTest.UserControl1"
         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" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300"
         DataContext="{Binding CardioVM, Source={StaticResource Locator}}">
<Grid>
    <ComboBox ItemsSource="{Binding CardioList, Mode=OneWay}" SelectedItem="{Binding SelectedCardio, Mode=TwoWay}"  Height="50"></ComboBox>

</Grid>

and here is the code for my CardioVM:

    public class CardioVM : ViewModelBase
{
    public Cardio cardioItem { get; set; }
    public CardioVM()
    {
        TestLabel = "Tester";
    }

    //Test Label for binding testing
    private string testLabel;

    public string TestLabel
    {

        get { return testLabel; }
        set
        {
            testLabel = value;
            RaisePropertyChanged("TestLabel");
        }
    }

    public CardioVM(string Date, string File)
    {

        cardioItem = new Cardio(File, Date);
        CardioList = new List<string>(cardioItem.exercises);

    }


   private List<string> cardioList;

   public List<string> CardioList
    {

        get { return cardioList; }
        set
        {
            cardioList = value;
            RaisePropertyChanged("CardioList");
        }
    }

   private string _selectedCardio;
   public string SelectedCardio
   {
       get { return _selectedCardio; }
       set
       {
           _selectedCardio = value;
           RaisePropertyChanged("SelectedCardio");
       }

   }

}

}

Not sure where I am going wrong here but any pointers would be much appreciated.

Here is where I thought I was adding in the userControl to a content control bound proprty in my Main view model:

 public void NewTemplateExecute()
    {
        TextHideTab = "Close"; 
       NewTemplateType = ("New " + SelectedExercise + " Exercise Template");
        //Set the message and lists based on the exercise selected plus adds the drop down control
       switch (SelectedExercise)
       {
           case "Cardio":
               ///
               //This is where I thought CardioVM was being added
               ///
               NewTemplateText = "Please choose a cardio exercise from the drop down list to the left. You can then select the duration of the exercise and the intensity. To add another exercise please press the plus button in the right hand corner";
               ExerciseDropDowns = new CardioVM(selectedDateLabel, @"Model\Repository\Local Data\CardioList.txt");

           break;
           case "Weights":
           NewTemplateText = "Please select a exercise type. you can refine your exercises by body area. Then add the number of sets and the reps per set. Add as many exercises as you like - dont forget to set to total duration";

           break;

           case "HIIT":
           NewTemplateText = "HIIT to add";
           break;
       }
       Messenger.Default.Send("NewTemplate");

    }

I had set the datacontext for CardioVM in my Mainwindow xaml as:

<DataTemplate DataType="{x:Type local:CardioVM}">
    <view:UserControl1/>
</DataTemplate>

I presume I have made a mistake in the way that I have hooked up CaridoVM but couldn’t seem to get it to databind unless I sent it through the VM locator

  • 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-10T08:16:20+00:00Added an answer on June 10, 2026 at 8:16 am

    Thanks to nemesv – you were of course spot on. Removed the DataContext from my CardioVM and now just using DataTemplate set in Main view to bind the Cardio view to the ViewModel. I can now call a cardioVM with parameters from the Mainview and it populates my combobox as expected. Seems I nbeeded to touch up on some of the basics of MVVM

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

Sidebar

Related Questions

So this one has me stumped; hopefully a kind soul can help me out.
This one has me stumped. I've searched and found similar questions but I can't
This one has me stumped, since I don't think this can be done with
This one has me stumped, and none of the other related questions here have
I'm not sure why this has stumped me. I have the following code $website
this is my first question. This has stumped me for 2 days. I have
This has had me stumped for a bit and I can't seem to figure
This has stumped me for some time. My problem: I have 2 different tables..
This has me stumped. I'm trying to figure out how to save the state
This has got me stumped, I've tried lots of different things, but I can't

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.