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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:38:12+00:00 2026-06-15T09:38:12+00:00

I have a simple search text box. This text box acts as a filter.

  • 0

I have a simple search text box. This text box acts as a filter. I’ve now copied/pasted the code for the 5th time and enough is enough. Time for a custom control.

left and right brackets have been replaced with ()

My custom control will be simple. My problem is I want to have a dependencyProperty on this control that is of type List(T).

I created a test project to proof it out and make sure it works. It works well. Ignore List.

Below is the entire class. The problem is that the only thing holding me up is replacing List (Person) with List(T). Something like List where: T is Object

typeof(List(T) where: T is Object) <= Obviously I can’t do that but gives an idea what I’m trying to accomplish.

public class SearchTextBox : TextBox
{
    public static readonly DependencyProperty SourceProperty =
        DependencyProperty.Register("FilterSource", typeof(List<Person>), typeof(SearchTextBox), new UIPropertyMetadata(null)); //I WANT THIS TO BE LIST<T>

    public List<Person> FilterSource
    {
        get
        {
            return (List<Person>)GetValue(SourceProperty);
        }
        set
        {
            SetValue(SourceProperty, value);
        }
    }

    public static readonly DependencyProperty FilterPropertyNameProperty =
        DependencyProperty.Register("FilterPropertyName", typeof(String), typeof(SearchTextBox), new UIPropertyMetadata());

    public String FilterPropertyName
    {
        get
        {
            return (String)GetValue(FilterPropertyNameProperty);
        }
        set
        {
            SetValue(FilterPropertyNameProperty, value);
        }
    }

    public SearchTextBox()
    {
        this.KeyUp += new System.Windows.Input.KeyEventHandler(SearchBox_KeyUp);
    }

    void SearchBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
    {
        ICollectionView view = CollectionViewSource.GetDefaultView(FilterSource);

        view.Filter = null;
        view.Filter = new Predicate<object>(FilterTheSource);
    }

    bool FilterTheSource(object obj)
    {
        if (obj == null) return false;

        Type t = obj.GetType();

        PropertyInfo pi = t.GetProperty(FilterPropertyName);

        //object o = obj.GetType().GetProperty(FilterPropertyName);

        String propertyValue = obj.GetType().GetProperty(FilterPropertyName).GetValue(obj, null).ToString().ToLower();

        if (propertyValue.Contains(this.Text.ToLower()))
        {
            return true;
        }

        return false;
    }
}
  • 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-15T09:38:13+00:00Added an answer on June 15, 2026 at 9:38 am

    No; that’s not possible.
    Instead, just use the non-generic typeof(IList).

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

Sidebar

Related Questions

I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have an asp.net web page with a simple search text box that returns
I have a simple search page with this text input form <form name=assetInput action=assetResult.jsp
I have a simple search box that it hidden until hover(over) and hides again
I have a simple search form with a box and a button. <form action
I have a simple rails search implemented in my app. At the time I
I have a simple script that does some search and replace. This is basically
In a pretty typical scenario, I have a 'Search' text box on my web
I have a simple control that has a masked text box: xmlns:extToolkit=http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended ... <extToolkit:MaskedTextBox
On simple forms with one text box pressing enter submits the form (and 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.