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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:18:06+00:00 2026-06-11T12:18:06+00:00

I am having trouble binding my View Model to my View . I am

  • 0

I am having trouble binding my View Model to my View. I am a beginner with MVVM, but I believe I am implementing my system (almost) correctly. I have a Model that contains data, which I am getting in my View Model, and then when my page is navigated to, I am attempting to grab that View Model data and binding it to the View.

My issue is that I have a ListBox in my View with 3 objects per item, and I cannot seem to bind to it correctly for each item in my list.

MainPage.xaml

<ListBox x:Name="FavoritesListBox" ItemsSource="{Binding FavoriteItems}" 
         SelectionChanged="FavoritesListBox_SelectionChanged">

    <StackPanel Orientation="Horizontal" Margin="12,0,12,0">
        <Image x:Name="favicon" Source="{Binding Favicon}" 
               Width="50" Height="50"/>
        <StackPanel>
            <TextBlock x:Name="favoritesName" Text="{Binding Name}" 
                       FontSize="{StaticResource PhoneFontSizeExtraLarge}"/>
            <TextBlock x:Name="favoritesAddress" 
                       Text="{Binding Address}" Margin="12,0,0,0"/>
        </StackPanel>
    </StackPanel>                
</ListBox>

MainPage.xaml.cs

public FavoritesPage()
    {
        InitializeComponent();

        // Set the data context of the listbox control to the sample data
        FavoritesListBox.DataContext = App.ViewModel;
    }

App.xaml.cs

private static MainViewModel viewModel = null;        

    public static MainViewModel ViewModel
    {
        get
        {
            // Delay creation of the view model until necessary
            if (viewModel == null)
                viewModel = new MainViewModel();

            return viewModel;
        }
    }

MainViewModel.cs

public ObservableCollection<ItemViewModel> FavoriteItems { get; private set; }

    public MainViewModel()
    {
        //FavoriteItems = new ObservableCollection<ItemViewModel>();
        FavoriteItems = Settings.FavoritesList.Value;
    }

Settings.cs (The Model)

public static Setting<ObservableCollection<ItemViewModel>> FavoritesList = 
    new Setting<ObservableCollection<ItemViewModel>>(
        "Favorites", 
        new ObservableCollection<ItemViewModel>());

ItemViewModel.cs

private string _favicon;
    public string Favicon
    {
        get
        {
            return _favicon;
        }
        set
        {
            if (value != _favicon)
            {
                _favicon = value;
                NotifyPropertyChanged("Favicon");
            }
        }
    }

    private string _name;
    public string Name
    {
        get
        {
            return _name;
        }
        set
        {
            if (value != _name)
            {
                _name = value;
                NotifyPropertyChanged("Name");
            }
        }
    }

    private string _address;
    public string Address
    {
        get
        {
            return _address;
        }
        set
        {
            if (value != _address)
            {
                _address = value;
                NotifyPropertyChanged("Address");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

..and this is where and how I am saving each item (which should have three properties listed in the ItemViewModel

void addToFavorites_Click(object sender, EventArgs e)
{
    var favoriteItem = 
        new ItemViewModel{
            Favicon = "", 
            Name = "", 
            Address = TheBrowser.currentUrl() };
        Settings.FavoritesList.Value.Add(favoriteItem);            
}

Where FavoritesList is populated using an ItemViewModel containing 3 objects. The list is being populated correctly because during debugging I can see the entities in FavoritesList, but I am having an issue calling these entities in the view model to show up in my ListBox in the view?

I believe I am binding incorrectly but I’m not sure how to fix this?

  • 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-11T12:18:07+00:00Added an answer on June 11, 2026 at 12:18 pm

    In your XAML you bind to paths Name and Address do you have these 2 properties defined in your ItemViewModel?

    Update after reading your code properly:

    You are not updating the datatemplate of the Items of the Listbox. This is what you need to do:

    <ListBox x:Name="FavoritesListBox" ItemsSource="{Binding FavoriteItems}" SelectionChanged="FavoritesListBox_SelectionChanged">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" Margin="12,0,12,0">
                    <Image x:Name="favicon" Source="{Binding Favicon}" Width="50" Height="50"/>
                    <StackPanel>
                        <TextBlock x:Name="favoritesName" Text="{Binding Name}" FontSize="{StaticResource PhoneFontSizeExtraLarge}"/>
                        <TextBlock x:Name="favoritesAddress" Text="{Binding Address}" Margin="12,0,0,0"/>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening, I'm having trouble with model binding and validation but I don't know
I am having trouble binding a Command that is generated up the UI tree
I'm having trouble implementing a tracking pixel script, specifically with binding the script to
I am having trouble with a single Wcf Service that we have in an
I am having trouble dealing with user registration in ASP.NET MVC3 Model Binding. Basically,
I have just started using WPF and am having trouble data binding from the
Hey. I've having some trouble with binding in XAML. I have a list of
I am having trouble with binding on emberjs. I have bound an ember textfield
Using jQuery 1.7 I'm having trouble binding a Click event to some dynamically loaded
I'm using Hibernate 4.0.1.Final. I'm having trouble binding a session when testing my service.

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.