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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:46:57+00:00 2026-06-17T22:46:57+00:00

I have a problem with listView initializations. The .xaml part of the listView is

  • 0

I have a problem with listView initializations. The .xaml part of the listView is as below,

<ListView x:Name="categoryListView" HorizontalAlignment="Left" Width="129" Height="180" 
              ItemsSource="{Binding Path=RecordModel.CategoryList}" 
              DisplayMemberPath="RecordModel.CategoryList" 
              SelectedValue="{Binding Path=RecordModel.RecordTitle}"
              VerticalAlignment="Top">

I have a list of String paths in RecordModel.CategoryList but I need to change the list at window initialization. Part of the view-model is below. Where can I add the code to change the list so the listView gets the changed list items at start?

public class MainWindowViewModel : ViewModelBase
{
...
private RecordModel _recordModel;
private ICommand _addCategoryCommand;
...

public MainWindowViewModel()
{
 _recordModel = new RecordModel();
}
public RecordModel RecordModel
{
  get { return _recordModel; }
  set { _recordModel = value; }
}
...
public ICommand AddCategoryCommand
{
 get
  {
   if (_addCategoryCommand == null)
       _addCategoryCommand = new AddCat ();
     return _addCategoryCommand;
  }
}

public class AddCat : ICommand
{
  public bool CanExecute(object parameter) { return true; }
  public event EventHandler CanExecuteChanged;
  public void Execute(object parameter)
  {
    MainWindowViewModel mainWindowViewModel = (MainWindowViewModel)parameter;
    ...
    //Do things with mainWindowViewModel and the variables it has
  }
...
  • 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-17T22:46:58+00:00Added an answer on June 17, 2026 at 10:46 pm

    This is the reason that ViewModels exist: so that they can transparently convert values from the Model to values more appropriate for binding.

    You should expose a CategoryList property on the MainWindowViewModel and bind directly on that. You can then populate it by processing the values of RecordModel.CategoryList in the RecordModel property setter:

    public class MainWindowViewModel : ViewModelBase
    {
        private RecordModel _recordModel;
    
        public MainWindowViewModel()
        {
            RecordModel = new RecordModel(); // set the property not the field
        }
    
        public RecordModel RecordModel
        {
            get { return _recordModel; }
            set {
                _recordModel = value;
                // populate CategoryList here from value.CategoryList
            }
        }
    
        public UnknownType CategoryList { get; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the xaml of listview <ListView Grid.Column=1 Height=auto Name=ListView1 Width=auto AllowDrop =True >
I have problem setting the height of a single row in a ListView. I
I have an problem to displaying text below listview.when items are more in list
I have a problem refreshing a ListView. I call my ListView Activity , I
I have a problem with list and listview. I started a project and added
I can't fix this problem on my listview template: i have the error as
I have the following problem. The background color in a ListView is set LightGreen
I have an activity which consists of a ListView . The problem is that
I have problem in Listview onListItemClick() method. I am not getting the position of
I have a problem with listview which list item contain a checkbox. When i

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.