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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:54:23+00:00 2026-06-17T15:54:23+00:00

Can anyone help me to create an ItemsSource property in my custom Silverlight UserControl?

  • 0

Can anyone help me to create an ItemsSource property in my custom Silverlight UserControl?

Here is my a quite simple ViewModel:

public class MyVM
{
    public ObservableCollection<int> Values { set; get; }

    public MyVM()
    {
        this.Values = new ObservableCollection<int>();
    }
}

This is my (inner) UserControl which I past into main UserContorl (MainPage):

<UserControl x:Class="SilverlightApplication1.SilverlightControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White" >
    <Border BorderBrush="Black" BorderThickness="2">
        <ListBox Margin="5" Name="lst" />
    </Border>
</Grid>
</UserControl>

public partial class SilverlightControl1 : UserControl
{
    public IEnumerable MyItemsSource
    {
        get
        {
            return (IEnumerable)GetValue(MyItemsSourceProperty);
        }
        set
        {
            SetValue(MyItemsSourceProperty, value);
        }
    }
    public static readonly DependencyProperty MyItemsSourceProperty =
        DependencyProperty.Register("MyItemsSource", typeof(IEnumerable), typeof(SilverlightControl1), new PropertyMetadata(null));


    public SilverlightControl1()
    {
        InitializeComponent();
    }
}

This is a small Container which hosts my UserControl:

<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:SilverlightApplication1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<Grid x:Name="LayoutRoot" Background="White">
    <local:SilverlightControl1 Name="qqq" MyItemsSource="{Binding Path=Values}"/>

</Grid>
</UserControl>

public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
        MyVM vm = new MyVM();
        vm.Values.Add(1);
        vm.Values.Add(2);
        vm.Values.Add(3);
        vm.Values.Add(4);

        this.DataContext = vm;
    }
}

How can I bind data to my inner ListBox?

  • 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-17T15:54:23+00:00Added an answer on June 17, 2026 at 3:54 pm

    I have stopped using UserControl completely, partly because of this. I use CustomControls instead. The usability and complaxity is exactly the same. You have possibiliity for codebehind and a separate model (although I mostly use the control’s code as the model itself setting this.DataContext = this;). My code also gets more structured (at least I think so) and I have more possibilities to change the UI for the control.

    The only disadvantage with using CustomControls is that I don’t have the design surface like you have in UserControls and Windows. The UI is put in the Generic.xaml file instead (be default) and built by writing XAML in the editor, opposed to using your mouse. That’s a bummer to start with, but I got used to it surprisingly fast.

    So my answer is that if you use CustomControls, you can do the exact same. The Bindings are written like this:

    MyItemsSource="{Binding RelativeSource="{RelativeSource Mode=TemplatedParent}" Path=Values}"
    

    …or simply:

    MyItemsSource="{TemplateBinding Values}"
    

    …if you don’t have to add any Converters or anything else to the Binding.

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

Sidebar

Related Questions

I'm new here. Can anyone help me for how create a form like this
Can anyone help me to create a simple viewing of cam using just a
Can anyone please help me to create a custom drop down similar to the
I need to create HTML pop-up menu using Perl. Can anyone help me?
I am trying to create a canvas with scroll bars. Can anyone help me
Can anyone please tell me how to write NSMutableArray of custom class objects to
Can anyone help me create a regular expression that accepts alphanumeric (numbers and letters
Can anyone help me to create a csv file from List, my scenario is,
can anyone help me.I cant create a new web application.I mean i cant find
Can anyone help me how to create a JSON Object from the database? This

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.