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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:39:09+00:00 2026-06-14T11:39:09+00:00

Can someone tell me why the way I am binding data here does not

  • 0

Can someone tell me why the way I am binding data here does not work? I was able to do this fine with using a GridView. I am not sure why the data is not being passed to the user control here, in addition it compiles fine and shows the user controls with there default text

Main.xaml.cs:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace ItemsControlSample
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        PopulateData(); 

    }

    public class someKindaOfDataHolder
    {
        public string Text1;
        public string Text2; 
    }

    private void PopulateData()
    {
        List<someKindaOfDataHolder> dataAndStuff = new List<someKindaOfDataHolder>(); 

        for (int i = 0; i < 5; ++i)
        {
            dataAndStuff.Add(new someKindaOfDataHolder()
            {
                Text1 = "data spot 1: " + i.ToString(),
                Text2 = "data spot 2: " + (i + 2).ToString() 
            }); 

        }

        ListOfAUserControls.ItemsSource = dataAndStuff; 
    }


}
}

Main.xaml

<Page
x:Class="ItemsControlSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ItemsControlSample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <ScrollViewer>
            <ItemsControl x:Name="ListOfAUserControls" ItemsSource="{Binding}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                        <local:CustomUserControl DynamicText1Text="{Binding Text1}"  DynamicText2Text="{Binding Text2}" Margin="0,0,10,0"/> 
                    </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,46,-50,0"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>

        </ItemsControl>
    </ScrollViewer>


</Grid>
</Page>

CustomUserControl.xaml.cs:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace ItemsControlSample
{
public sealed partial class CustomUserControl : UserControl
{


    public static readonly DependencyProperty DynamicText1Property =
     DependencyProperty.Register("DynamicText1Text", typeof(string), typeof(CustomUserControl), new PropertyMetadata(null, OnDynamicText1PropertyChanged));

    public string DynamicText1Text
    {
        get { return (string)GetValue(DynamicText1Property); }
        set { SetValue(DynamicText1Property, value); }
    }

    public static readonly DependencyProperty DynamicText2Property =
     DependencyProperty.Register("DynamicText2Text", typeof(string), typeof(CustomUserControl), new PropertyMetadata(null, OnDynamicText2PropertyChanged));

    public string DynamicText2Text
    {
        get { return (string)GetValue(DynamicText2Property); }
        set { SetValue(DynamicText2Property, value); }
    }

    public CustomUserControl()
    {
        this.InitializeComponent();
    }

    private static void OnDynamicText1PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var obj = d as CustomUserControl;
        obj.DynamicText1.Text = e.NewValue.ToString();
    }

    private static void OnDynamicText2PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var obj = d as CustomUserControl;
        obj.DynamicText2.Text = e.NewValue.ToString();
    }
}
}

CustomUserControl.xaml:

<UserControl
x:Class="ItemsControlSample.CustomUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ItemsControlSample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="800"
d:DesignWidth="800">

<Grid Background="Blue">
    <Grid.RowDefinitions>
        <RowDefinition Height="6*"/>
        <RowDefinition Height="2*"/>
    </Grid.RowDefinitions>

    <Image  Source="ms-appx:///Assets/MSIcon.png" />
    <StackPanel Grid.Row="1"   Margin="25">
        <TextBlock Text="Obay" FontSize="45" />
        <TextBlock x:Name="DynamicText1" Text="DynamicText1" FontSize="35" />
        <TextBlock x:Name="DynamicText2" Text="DynamicText2" FontSize="35" />
    </StackPanel>
</Grid>
</UserControl>

Thanks!

  • 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-14T11:39:11+00:00Added an answer on June 14, 2026 at 11:39 am

    You need to set the DataContext somewhere. Without it – your bindings have no context and they fail (look at the Output window in VS when debugging Debug builds to see binding errors). You are setting ItemsSource=”{Binding}” where the binding has no context.

    Then again – you are overriding the ItemsSource elsewhere with your “ListOfAUserControls.ItemsSource = dataAndStuff;” call, so that is likely not the issue causing your problem in the end. The DataContext of an item in an ItemsControl should be set automatically to an item in the ItemsSource collection.

    Another problem that might block you there is that someKindaOfDataHolder.Text1 in your case is a field and it should be a property to work with bindings – try this instead:

    public string Text1 { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me why this processes all the files and then does it
I am using SAXON JAVA API. Can someone tell me a way how to
Can someone tell me why this is not working? Throughout my document I have
Can someone tell me how to change directories using FtpWebRequest? This seems like it
Can someone tell me of a way in which I can add a user
Can someone tell me the correct way of passing multiple vectors to a function
Can someone tell me if there is a way for me to use the
Can someone who is way smarter than I tell me what I'm doing wrong..
Can someone tell me how to modify this regex to allow periods in a
can someone tell me what seems to be the issue with this <?php $increment

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.