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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:20:24+00:00 2026-05-26T12:20:24+00:00

I can’t get my xaml to bind with my viewmodel. I have in my

  • 0

I can’t get my xaml to bind with my viewmodel. I have in my viewModel a ObservableCollection of a INotifyPropertyChanged class that holds data about a recepie. Here is my Recepie class :

namespace WP7SQLiteClient.Model
{
    public class MainViewModelItem : INotifyPropertyChanged
    {
        string _title, _subTitle, _imageUriPath;

        string title
        {

            get
            {
                return _title;
            }
            set
            {
                _title = value;
                NotifyPropertyChanged("title");
            }
        }
        string subTitle
        {
            get
            {
                return _subTitle;
            }
            set
            {
                _subTitle = value;
                NotifyPropertyChanged("subTitle");
            }
        }
        string imageUriPath
        {
            get
            {
                return _imageUriPath;
            }
            set
            {
                _imageUriPath = value;
                NotifyPropertyChanged("imageUriPath");
            }
        }

        public MainViewModelItem(string title, string subtitle, string imageuripath)
        {
            this.title = title;
            this.subTitle = subtitle;
            this.imageUriPath = imageuripath;
        }

        public event PropertyChangedEventHandler PropertyChanged;

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

And my ViewModel which holds the list of recepies :

namespace WP7SQLiteClient.ViewModel
{

        public class PanoramaViewModel : INotifyPropertyChanged
        {
            public ObservableCollection<MainViewModelItem> _recepiesList;


            public ObservableCollection<MainViewModelItem> recepiesList
            {
                get
                {
                    return _recepiesList;
                }

                set
                {
                    _recepiesList = value;
                    NotifyPropertyChanged("recepiesList");
                }
            }

            public PanoramaViewModel()
            {
                this.recepiesList = new ObservableCollection<MainViewModelItem>();

            }

            public bool IsDataLoaded
            {
                get;
                private set;
            }

            public void LoadData()
            {
                this.recepiesList.Add(new MainViewModelItem("Classics", "", ""));
                this.recepiesList.Add(new MainViewModelItem("Perfect Pasta", "", ""));
                this.recepiesList.Add(new MainViewModelItem("Favorites", "", ""));
                this.recepiesList.Add(new MainViewModelItem("Snacks & Antipasti", "", ""));
                this.recepiesList.Add(new MainViewModelItem("Desserts", "", ""));
                this.recepiesList.Add(new MainViewModelItem("3 minutes recipes", "", ""));

                this.IsDataLoaded = true;
            }


            private string _sampleProperty = "Sample Runtime Property Value";
            /// <summary>
            /// Sample ViewModel property; this property is used in the view to display its value using a Binding
            /// </summary>
            /// <returns></returns>
            public string SampleProperty
            {
                get
                {
                    return _sampleProperty;
                }
                set
                {
                    if (value != _sampleProperty)
                    {
                        _sampleProperty = value;
                        NotifyPropertyChanged("SampleProperty");
                    }
                }
            }




            public event PropertyChangedEventHandler PropertyChanged;

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

}

In my MainPage.xaml (it’s in the root of the project, the viewModel is in the ViewModel folder and the Model is in the Model folder) i have my listbox declared like this :

<ListBox x:Name="recepiesList"  ItemTemplate="{StaticResource ListViewModelTemplate}" > 

                </ListBox>

The template is located in the App.xaml and is correct for sure. It uses things like {Binding title}

In the MainPage.cs i try to link the view model with the page using :

public static PanoramaViewModel viewModel = null;

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

                return viewModel;
            }
        } 
public MainPage()
        {

            InitializeComponent();

            ViewModel.LoadData();
            DataContext = ViewModel;

        }

But it doesn’t work, nor the debugger raises an error. How can i correctly link the viewmodel with the xaml ?

UPDATE my template looks like this :

<DataTemplate x:Key="ListViewModelTemplate"> <!-- for recent recepies-->

            <Grid Width="400" Height="80" VerticalAlignment="Center">

                <StackPanel Orientation="Vertical">
                    <Border CornerRadius="0" x:Name="brdTesat" BorderBrush="Black" BorderThickness="1" Width="80" Height="80">

                    <Border.Background>
                        <ImageBrush x:Name="backgroundImaageBrush" Stretch="Fill">

                            <ImageBrush.ImageSource>

                                    <BitmapImage x:Name="bmapBackground" UriSource="{Binding imageUriPath}" >
                                </BitmapImage>

                            </ImageBrush.ImageSource>
                        </ImageBrush>
                    </Border.Background>
                </Border>
                    <StackPanel>
                    <TextBlock TextAlignment="Left" Margin="7,4,4,4" Text="{Binding title}" TextWrapping="Wrap"></TextBlock>
                        <TextBlock TextAlignment="Left" Margin="7,4,4,4" Text="DA" TextWrapping="Wrap"></TextBlock>
                    </StackPanel>
                </StackPanel>

            </Grid>
        </DataTemplate>

UPDATE 2

i’ve changed my listbox code to :

<ListBox x:Name="recepiesList"  ItemsSource="{Binding recepiesList}" >             </ListBox>

With no template, i get a list of [project_name].Model.MainViewModelItem, so i think there is a problem with the template.. What am i doing wrong?

  • 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-26T12:20:25+00:00Added an answer on May 26, 2026 at 12:20 pm

    You need to bind you ListBox to the data. So, this should work for you.

    <ListBox x:Name="recepiesList" ItemsSource="{Binding recepiesList}" ItemTemplate="{StaticResource ListViewModelTemplate}"  />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can find why i get this error can someone help? package Android.data; public class
Can I have a project that has some parts written in c and other
Can't get over it, no matter how much I search. I have AlarmManager, where
Can anybody let me know about a couple of open source projects that uses
Can I order my users in the database, so I don't have to say
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can any one tell, how to get the result of LINQ query contains group
Can I be sure about the order in a Python dictionary? The function op.GetTangent(id)
I have a jquery bug and I've been looking for hours now, I can't
Can I call select before recv_from on a socket that is blocking?

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.