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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:10:03+00:00 2026-05-26T10:10:03+00:00

I have a listbox, with custom items. Code: <ListBox Height=600 HorizontalAlignment=Left Margin=7,6,0,0 Name=friendList VerticalAlignment=Top

  • 0

I have a listbox, with custom items. Code:

<ListBox Height="600" HorizontalAlignment="Left" Margin="7,6,0,0" Name="friendList" VerticalAlignment="Top" Width="449" ItemsSource="{Binding Friends}">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="5,0">
                        <Image Height="120" HorizontalAlignment="Left" Name="image" Stretch="Fill" VerticalAlignment="Top" Width="120" Source="{Binding ImageUri}" GotFocus="image_GotFocus"/>
                        <CheckBox Height="78" HorizontalAlignment="Left" Margin="65,63,0,0" x:Name="selectedChckbox" VerticalAlignment="Top" Width="55" IsChecked="{Binding Selected, Mode=TwoWay}"/>
                        <TextBlock Height="58" HorizontalAlignment="Left" Margin="0,122,0,0" x:Name="nameTextBlck" VerticalAlignment="Top" Text ="{Binding Title}" Width="120" TextWrapping="Wrap" GotFocus="name_GotFocus"/>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

I’ve created a veiwmodel for the values for binding, and when I click on one item I want to change the checkbox state like so:

friendSelectionViewModel.Friends[_selectFriendContent.friendList.SelectedIndex].Selected = !friendSelectionViewModel.Friends[_selectFriendContent.friendList.SelectedIndex].Selected;

The ViewModel Code:

   public class FacebookFriendSelectionViewModel : INotifyPropertyChanged
{
    public FacebookFriendSelectionViewModel()
    {
        Friends = new ObservableCollection<TempFriends>();
    }
        /// <summary>
    /// A collection for MenuItemViewModel objects.
    /// </summary>
    public ObservableCollection<TempFriends> Friends { get; private set; }

    public void AddItem(TempFriends item)
    {
        Friends.Add(item);
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

}
public class TempFriends
{
bool _selected;

public string Title { get; set; }

public string ImageUri { get; set; }

public bool Selected {
    get
    {
        return _selected;
    }
    set 
    {
        _selected = value;
        OnPropertyChanged("Selected");
    }
}

public string Id { get; set; }


public TempFriends(string title, string imageUir, bool selected, string id)
{
    Title = title;
    ImageUri = imageUir;
    _selected = Selected = selected;
    Id = id;
}

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged(String info)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(info));
    }
}

But the only way the listbox gets the values updated, if I set the datacontext to null and than assign the viewmodel aggain like so:

  _selectFriendContent.DataContext = null;
    _selectFriendContent.DataContext = friendSelectionViewModel;

But this takes about 5-10 seconds to refresh the list. I know there is a better solution, I just cant figure out how.

Thanks in advance!

  • 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-26T10:10:03+00:00Added an answer on May 26, 2026 at 10:10 am

    TempFriends class doesn’t implement INotifyPropertyChanged as far as I see. Just add public class TempFriends : INotifyPropertyChanged

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

Sidebar

Related Questions

I have no idea why this code works fine: <ScrollViewer Height=674 HorizontalAlignment=Left VerticalAlignment=Top Width=480
I have a ListBox in WPF application as : <ListBox HorizontalAlignment=Left Margin=16,37,0,16 Name=lbEmpList Width=194
I have a listbox that displays Shipment Items (custom class) that are formatted using
I have a custom panel for a listbox <ItemsPanelTemplate x:Key=FloatPanelTemplate> <Controls:FloatPanel x:Name=CardPanel /> </ItemsPanelTemplate>
I have a listbox where the items contain checkboxes: <ListBox Style={StaticResource CheckBoxListStyle} Name=EditListBox> <ListBox.ItemTemplate>
I have a ListBox which displays items of variable height. I want to show
I have a ListBox displaying items with a template something like this: <ListBox x:Name=CustomerResultList
I have ListBox with custom template, how do programmatically scroll it down to bottom?
i have to validate listbox for maximum of three items to select by the
I have 2 listboxes, the first listbox stores data pointers for each items Object

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.