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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:37:16+00:00 2026-05-11T21:37:16+00:00

the problem is pretty easy if you reduce it to one class. Given the

  • 0

the problem is pretty easy if you reduce it to one class. Given the following image, I want to create a simple two sided control, which puts items from one list into the other depending on a boolean value.

EDIT: You can of course click on items in both lists, and the item switches to the other list. Also, a callback is called, in case I need to update some DB stuff…

I created a nice picture to movivate you a little bit, because I am stuck…

The world is not so simple like the example: How would you solve this for various classes.

Imagine a class like “Car” with “IsFast”. Or a class like “Fruits” with “ILikeIt”. I do not want to reprogramm the WPF control each time, I need some way to bind… (oh, I think I just got an idea)… but still, is there any good practice how to allow generic classes (like T) as long as they implement certain properties.. Or a wrapper class?

I have no idea, how would you solve it. Simple binding with OnClick Functions seems not enough… Not sure… And, by the way, “write 3 controls” IS a suitable answer. If it is simpler, just tell me.

alt text http://img31.imageshack.us/img31/96/listexample.png

  • 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-11T21:37:17+00:00Added an answer on May 11, 2026 at 9:37 pm

    I think I understand what you are after, this should get you started.

    I am assuming that your usercontrol has two listviews, one intended for the true items named “TrueList”, the other for the false items named “FalseList”.

    Extend your usercontrol from ItemsCollection and bind the ItemsSource property of each listview to the ItemsSource of the parent usercontrol.

    Add a TrueFilter and a FalseFilter property to your usercontrol:

       Predicate<object> trueFilter;
       public Predicate<object> TrueFilter
       {
            get
            {
                 return trueFilter;
            }
            set 
            {
                 if (trueFilter!= null && this.TrueList.Items != null)
                     this.TrueList.Items.Filter -= trueFilter;
    
                 trueFilter = value;
    
                 if (trueFilter!= null && this.TrueList.Items != null)
                     this.TrueList.Items.Filter += trueFilter;
            }
        }
    
       Predicate<object> falseFilter;
       public Predicate<object> FalseFilter
       {
            get
            {
                 return falseFilter;
            }
            set 
            {
                 if (falseFilter!= null && this.FalseList.Items != null)
                     this.FalseList.Items.Filter -= falseFilter;
    
                 filter = value;
    
                 if (falseFilter!= null && this.FalseList.Items != null)
                     this.FalseList.Items.Filter += falseFilter;
            }
        }
    

    Then create an “IToggle” (or some other more meaningful name) interface:

    public interface IToggle
    {
       Predicate<object> TrueFilter { get; }
       Predicate<object> FalseFilter { get; }
    }
    

    Then, extend ObservableCollection for each of your custom classes, implementing the “IToggle” interface:

    public class Cars : ObservableCollection<Car>, IToggle
    {
        Predicate<object> trueFilter;
        public Predicate<object> TrueFilter
        {
            get
            {
                if (trueFilter == null)
                   trueFilter = new Predicate<object>(this.TrueFilterPredicate);
                return trueFilter;
            }
        }
    
        private bool TrueFilterPredicate(object value)
        {
           Car car = (Car)value;
           return car.IsFast;
        }
    
        Predicate<object> falseFilter;
        public Predicate<object> FalseFilter
        {
            get
            {
                if (falseFilter == null)
                   falseFilter = new Predicate<object>(this.FalseFilterPredicate);
                return falseFilter;
            }
        }
    
        private bool FalseFilterPredicate(object value)
        {
           Car car = (Car)value;
           return !car.IsFast;
        }
    

    Next, override the ItemsSource property on your user control:

    public new IEnumerable ItemsSource
    {
       get { return base.ItemsSource; }
       set
       {
            if (value != null && !(value is IToggle))
               throw new Exception("You may only bind this control to collections that implement IToggle.");
    
            base.ItemsSource = value;
    
            this.TrueFilter = base.ItemsSource == null ? null : (base.ItemsSource as IToggle).TrueFilter;
            this.FalseFilter = base.ItemsSource == null ? null : (base.ItemsSource as IToggle).FalseFilter;
       }
    }
    

    Finally, call TrueList.Items.Refresh() and FalseList.Items.Refresh() on your event callbacks to refresh the item views whenever you switch an item from true to false, and vice versa.

    This solution still requires writing some implementation code for each custom class (the true and false filters), but it should keep the extra code to a minimum.

    Alternatively, it would be a much simpler solution if you gave each of your custom classes a common interface, something like:

    public interface Valid
    {
       bool IsValid { get; set; }
    }
    

    Then you could use a single set of filters (or style setters, or databinding with converters) to work against the “Valid” interface. Instead of “Car.IsFast” and “Fruit.ILikeIt” you would use “Car.IsValid” and “Fruit.IsValid”.

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to create the delegate explicitly – and you… May 12, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer Absolutely correct. You have to release the (retain) properties in… May 12, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer The Microsoft Dynamics CRM application on premise version uses Active… May 12, 2026 at 1:03 am

Related Questions

When I write an app, I use the System.Data interfaces (IDbConnection, IDbCommand, IDataReader, IDbDataParameter,
Possible Duplicate: C# 'var' keyword versus explicitly defined variables EDIT: For those who are
I'm preparing to go to a computer science contest by completing problems from past
Couldn't find an answer to this one. I have a WPF ListView control that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.