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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:06:34+00:00 2026-05-31T10:06:34+00:00

Relatively new to C# and MVVM, but I’m making a WP7 app using the

  • 0

Relatively new to C# and MVVM, but I’m making a WP7 app using the MVVM Light Toolkit. I’m having a problem with twoway binding of a property in a ListBox. I have an ObservableCollection of clients and I’m trying to select an individual client (which when clicked will bring me to a new ViewModel).

When I click on a selected item, it should update the SelectedItem property and set the value to the client clicked. However, when clicked it doesn’t even get to the setter (I have marked the break point with an *). Does anyone know where I’ve gone wrong or have a better proposed solution? I have been trawling this place for hours!

XAML MarkUp:

        <ListBox SelectedItem="{Binding SelectedItem, Mode=TwoWay}" ItemsSource="{Binding ClientList, Mode=TwoWay}" x:Name="FirstListBox" Margin="0,0,-12,0" ScrollViewer.VerticalScrollBarVisibility="Auto">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="0,0,0,17" Width="432">
                    <Button CommandParameter="{Binding}">
                        <helper:BindingHelper.Binding>
                            <helper:RelativeSourceBinding Path="ShowClientCommand" TargetProperty="Command"
                                    RelativeMode="ParentDataContext" />
                        </helper:BindingHelper.Binding>
                        <Button.Template>
                            <ControlTemplate>
                                <TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

ViewModel Properties:

    public ObservableCollection<Client> ClientList
    {
        get 
        {
            return _clientList;
        }
        set 
        {
            _clientList = value;
            RaisePropertyChanged("ClientList");
        }
    }

    public Client SelectedItem
    {
        get
        {
            return _selectedItem;
        }
        set
        {
         *   _selectedItem = value;
            RaisePropertyChanged("SelectedItem");
        }
    }
  • 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-31T10:06:36+00:00Added an answer on May 31, 2026 at 10:06 am

    Could it be that because you aren’t signed up for the selection_changed event it isn’t changing the property?

    I’m not completely sure why that isn’t working but here’s a solution that I always use and that the templates recommend.

    Sign your listbox up for the SelectionChanged event like so:

    <ListBox SelectionChanged="FirstListBox_SelectionChanged" ItemsSource="{Binding ClientList, Mode=TwoWay}" x:Name="FirstListBox" Margin="0,0,-12,0" ScrollViewer.VerticalScrollBarVisibility="Auto">
    

    Then in the corresponding .cs file, have a handler that looks like this:

    private void FirstListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // If selected index is -1 (no selection) do nothing
        if (FirstListBox.SelectedIndex == -1)
            return;
    
        // get the client that's selected
        Client client = (Client) FirstListBox.selectedItem;
    
        //... do stuff with the client ....
    
        // reset the index (note this will fire this event again, but
        // it'll automatically return because of the first line
        FirstListBox.SelectedIndex = -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MVVM Light toolkit Messenger class- A Messenger class (and diverse message
I'm relatively new to using WPF and the MVVM architecture. I have a question
I'm relatively new to Python and am having problems programming with Scapy, the Python
I'm relatively new to MVVM and I'm trying to understand how INotifyPropertyChanged interface works
Im relatively new to PHP but have realized it is a powerfull tool. So
Hi I'm relatively new to Android programming but I would be grateful of some
Relatively new to Cocoa here. This question is about NSFileHandle, but I got a
I'm relatively new to .NET and MVC3. I'm having some trouble with the above
I relatively new to using Eclipse with the Android SDK. Whenever I encounter an
I am relatively new to Objective-C and now I have a problem in my

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.