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

  • Home
  • SEARCH
  • 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 812869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:16:10+00:00 2026-05-15T01:16:10+00:00

So i have a listbox: <ListBox x:Name=listbox HorizontalAlignment=Left Margin=8,8,0,8 Width=272 BorderBrush={x:Null} Background={x:Null} Foreground={x:Null} ItemsSource={Binding

  • 0

So i have a listbox:

<ListBox x:Name="listbox" HorizontalAlignment="Left" Margin="8,8,0,8" Width="272" BorderBrush="{x:Null}" Background="{x:Null}" Foreground="{x:Null}" ItemsSource="{Binding MenuItems}" ItemTemplate="{DynamicResource MenuItemsTemplate}" SelectionChanged="ListBox_SelectionChanged" SelectedItem="{Binding SelectedItem}">

</ListBox>

and i have this included in my viewmodel:

    public ObservableCollection<MenuItem> MenuItems
    {
        get
        {
            return menuitems;
        }
        set
        {
            menuitems = value;
            NotifyPropertyChanged("MenuItems");
        }
    }
    public MenuItem SelectedItem
    {
        get
        {
            return selecteditem;
        }
        set
        {
            selecteditem = value;
            NotifyPropertyChanged("SelectedItem");
        }
    }

and also in my viewmodel:

    public void UpdateStyle()
    {
        ActiveHighlight = SelectedItem.HighlightColor;
        ActiveShadow = SelectedItem.ShadowColor;
    }

So, the objective is to call UpdateStyle() whenever selectedchanged event is fired. So in the .CS file, i call UpdateStyle().
The problem is, whenever I get into the selectionchanged event method, my ViewModel.SelectedItem is always null.
I tried debugging this to see if the binding was working correctly, and it is. When I click on an item in the listbox, the SelectedItem Set is triggered, setting the value… but somewhere inbetween that and the selected changed (In the CS File) It gets reset to Null.

Can anyone help out?

Thanks

Edit:
I thought I might shed a little more light.
1. Click on an item in the list
2. SelectedItem.Set gets triggered, ViewModel.SeletedItem gets set correctly.
3. Enter the OnSelectionChanged Event in the .CS file.
4. Enter ViewModel.UpdateStyle()
5. SelectedItem Throws a Null Exception.

  • 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-15T01:16:10+00:00Added an answer on May 15, 2026 at 1:16 am

    Wow, found a strange issue:

    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource MainViewModelDataSource}}" d:DataContext="{d:DesignData /SampleData/MainViewModelSampleData.xaml}">
    

    That code is generated by Expression Blend – and it was causing the issue. I erased all generated binding and just made a this.datacontext a new VM in the constructor of the XAML… now its working.

    Thanks anyway, guys.

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

Sidebar

Ask A Question

Stats

  • Questions 489k
  • Answers 489k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can start with a child selector (>) when using… May 16, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer oh, never mind. dumb move on my part. this metadata… May 16, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer UglifyJS2, used by the jQuery project. May 16, 2026 at 9:02 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a ListBox in WPF application as : <ListBox HorizontalAlignment=Left Margin=16,37,0,16 Name=lbEmpList Width=194
I have listbox that displays information about list of objects: <ListBox Grid.Column=0 Height=152 Name=CustomersList
I have a WPF ListBox with a defined DataTemplate. In that template, I have
I have a ListBox with a StackPanel that contains an image and label. <ListBox.ItemsPanel>
I have a ListBox containing a group of 'Expander' items, and what I would
I have a ListBox in Silverlight that has a list of items inside. Each
I have a ListBox when one of the ListBoxItems are selected I want to
in my Silverlight 4 Application, I have an observable list of a user defined
here is what I would like to do. I get a List of objects
My code behind file receives an instance object Session which has a property AvailableCountries

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.