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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:33:06+00:00 2026-06-17T19:33:06+00:00

I am trying to do some simple data binding in XAML but it is

  • 0

I am trying to do some simple data binding in XAML but it is not working for me and I am not sure why.

I have this gridview

 <GridView Name="test2">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Header}" FontWeight="Bold" Style="{StaticResource ItemTextStyle}"/>
                        <TextBlock Text="{Binding Item}" FontWeight="Bold" Style="{StaticResource ItemTextStyle}"/>
                    </StackPanel>
                </DataTemplate>
            </GridView.ItemTemplate>
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
        </GridView>

I am trying to now bind. I tried to do it in XMAL(it crashes) and through C# code(Nothing happens)

In the code behind constructor I tried to do this

 public MyPage()
        {
            this.InitializeComponent();

            Test t = new Test
            {
                Header = "Header 1",
                Item = "Item 1",

            };

            List<Test> ts = new List<Test>();
            ts.Add(t);
            test2.DataContext = t;

        }

I also tried to pass it an collection as well.

As I said I could not get the XMAL way to do it at all.

  • 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-17T19:33:07+00:00Added an answer on June 17, 2026 at 7:33 pm

    The minimum to get this to work is to add the line:

    test2.ItemsSource = ts;
    

    But you’ve got few things that may cause you problems later.

    1. The DataContext setting doesn’t make much sense here, you’re saying that you’re going to make a single item the context for elements you’re bind to a grid. Typically, I’d say the DataContext would be a class that contains your collection of Tests – that would be the DataContext of your page, for instance, then you’d have

      <GridView Name=”test2″ ItemsSource=”{Binding Tests}”>

      where Tests is a property of whatever class you use as the DataContext. You want to make the DataContext the only thing you set in code, then everything else flows from the bindings.

    2. Instead of List, you probably want to use ObservableCollection, so that the data binding engine will automatically be informed when items are added and removed from the collection.

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

Sidebar

Related Questions

i have a simple template that i populate with some data then im trying
I am trying to make a (very) simple Data Binding test, but it doesn't
Trying a simple project to create my own (very basic) data binding. I have
I'm trying to use GET variables to transfer some simple data but for some
I am trying to implement some very simple Data Binding in my User Control
I'm trying to save some specific JSon data and store them in a simple
I am trying to create some simple polygons in openGL3.3. I have 2 types
We have an app that uses simple one way binding with a GridView to
This should be a very simple case, but I am pulling hair trying to
I'm trying to post some very simple data to a php file using jquery

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.