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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:25:40+00:00 2026-06-14T08:25:40+00:00

I am Using MVVM Pattern. when I select a Country from the listbox1 then

  • 0

I am Using MVVM Pattern.

when I select a Country from the listbox1 then second listbox
will display states from the selected country.

ListBox For Country

 <pmControls:pmListBox  x:Name="countryListBox"  Grid.Row="1" Margin="3" ItemsSource="{Binding Countries}" SelectedItem="{Binding SelectedCountry,Mode=TwoWay}"  >
                <pmControls:pmListBox.ItemTemplate >
                    <DataTemplate >
                        <Button  Command="{Binding DataContext.GetAllStatesCommand,ElementName=countryListBox}"  Margin="3" Width="100" Height="25" Content="{Binding Title}" >                                            
                        </Button>

                    </DataTemplate>
                </pmControls:pmListBox.ItemTemplate>
            </pmControls:pmListBox>

ListBox For State

<pmControls:pmListBox x:Name="stateListBox" Grid.Row="1" Margin="3" ItemsSource="{Binding States}">

                    <pmControls:pmListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding StateTitle}" ></TextBlock>
                        </DataTemplate>
                    </pmControls:pmListBox.ItemTemplate>
                </pmControls:pmListBox>

In ModelView these are my commands:

command to get all Countries:

public void getCountries()
{
    CountryServiceClient client = new CountryServiceClient();
client.GetCountryDetailsCompleted += (clientS, eventE) =>
{
    if (eventE.Error == null)
        {
        foreach (var item in eventE.Result)
        {
         countries.Add(item);
        }
    }
};
client.GetCountryDetailsAsync();

}

command to get all states for selected Country:

public void ExecutegetAllStatesCommand(EventToCommandArgs args)
{
    selectedState = new States();
    states = new ObservableCollection<States>();
            int cntry_id = this.SelectedCountry.Country_Id;

            StateServiceClient client = new StateServiceClient();
            client.GetStatesCompleted += (clientS, eventE) =>
            {
                if (eventE.Error == null)
                {
                    foreach (var item in eventE.Result)
                    {
                        states.Add(item);

                    }
                }
            };

        client.GetStatesAsync(cntry_id);
        }

Here i got the data correctly in my list states but it doesnt appears on Xaml.
Please help.

  • 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-14T08:25:41+00:00Added an answer on June 14, 2026 at 8:25 am

    You mentioned that the ‘states’ are being set correctly in the viewmodel, in that case the problem could be one of the following:

    1. I noticed you are binding to ‘States’ (upper case S) and your code behind sets to ‘states’ (lower case S).
    2. Have you implemented the INotifyPropertyChanged for the viewmodel and call the propertychanged event handler
    3. Try handling the CollectionChanged of the ObservableCollection that you are adding States to as the propertychanged will not automatically trigger when adding items.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to get ItemsControl display items selected Item textbox text value using MVVM pattern?
My WPF application is structured using the MVVM pattern. The ViewModels will communicate asynchronously
I'm writing an application in WPF using the MVVM-pattern and will really often use
I'm developing a WPF application using the MVVM pattern and I need to display
I forked from thread When using MVVM pattern, should code relating to property changes
I am using a mvvm pattern for an application that sources its data from
I'm trying to folow the mvvm pattern. When using galasoft EventToCommand i'm getting then
I am using MVVM pattern and I have one DataGrid with a column which
Using the MVVM pattern creating WPF applications you have the ViewModel providing data to
I am writing an application using the MVVM pattern. I am providing data to

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.