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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:59:15+00:00 2026-05-23T01:59:15+00:00

Can you bind in XAML to a Class that takes a type T? If

  • 0

Can you bind in XAML to a Class that takes a type T?

If I have a class myCLASS<T> and I want to bind a List<myClass<int>> to XAML can you do it?

Or do you have to write a wrapper class newMyClass: myClass<int> and then bind the XAML to newMyClass?

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-05-23T01:59:15+00:00Added an answer on May 23, 2026 at 1:59 am

    The WPF binding subsystem supports any type of object, structures, classes, generic classes and even dynamic objects. All that matters is that the instances have properties.

    You cannot create generic classes in the resources of a typical WPF application because the object creation syntax does not support it. Nevertheless, objects that are created in code-behind, in your view-model, or by services (even if they are instances of generic types or nested generic types), can still participate in binding.

    Here’s an example based on the question. Here’s some XAML for a window:

    <Grid>
        <ListBox ItemsSource="{Binding}" Padding="10">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding X}"/>
                        <TextBlock Text=" , "/>
                        <TextBlock Text="{Binding Y}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
    

    and here’s a generic class that resembles a Point class:

    class myClass<T>
    {
        public T X { get; set; }
        public T Y { get; set; }
    }
    

    and here is some code-behind to support the binding in the XAML above:

    void Window_Loaded(object sender, RoutedEventArgs e)
    {
        DataContext = new List<myClass<int>>
        {
            new myClass<int> { X = 1, Y = 2 },
            new myClass<int> { X = 3, Y = 4 },
        };
    }
    

    and this is what it looks like:

    Generic Binding

    We created instances of the generic class in the code-behind but bound to that data using XAML.

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

Sidebar

Related Questions

I have the below xaml that I am trying to bind to my class.
I have a user control where the XAML of the control can bind to
I've an ASP.Net 2.0 Gridview control that I can bind a List<T> too, for
I have an ObservableCollection<Object> that contains two different types. I want to bind this
I have an Entity result of List<string> GetTagsData that I need to somehow bind
I can't get my xaml to bind with my viewmodel. I have in my
Hey. I have a list of items that the user can search. The search
so I have a custom class in a list. I can't seem to get
To bind to the current DataContext in XAML you can use: <TextBlock Text={Binding} />
I can bind a jquery event to this element like: <script type=text/javascript> $('#new_key').ready(function() {

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.