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

  • Home
  • SEARCH
  • 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 6707327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:37:33+00:00 2026-05-26T07:37:33+00:00

I define this simple class public class SimpleClass { public string Val1 {get;set;}; public

  • 0

I define this simple class

 public class SimpleClass
 {
      public string Val1 {get;set;};
      public string Val2 {get;set;}
      public string Res
      {
            get
            {
                 string.Format("{0}_{1}", Val1, Val2 );
            }
      }

      public SimpleClass(string v1, string v2)
      {
             Val1 = v1;
             Val2 = v2;
      }

      public SimpleClass(string v1, int i)
      {
            if(i == 0)
            {
                 Val1 = v1;
                 val2 = "";
            }

            if(i == 0)
            {
                 Val2 = v1;
                 val1 = "";
            }
      }


 }

Now, i define in the code this

 List< SimpleClass > myList = new List<SimpleClass>();
 myList.Add(new SimpleClass("a1", "b1");
 myList.Add(new SimpleClass("a2", "b2");
 myList.Add(new SimpleClass("a3", "b3");
 myList.Add(new SimpleClass("a4", "b4");

And i define in the xaml 2 ListBox –
First that show all the a1…a4 items
Second that show all the b1…b4 items

Each item in the ListBox is CheckBox – and the content is the string of the item.

Now i want to define filter that will show in some other list only the SimpleClass.Res that was checked in the listBox.

==> that mean that if in the listBox that items that was checked are b1 and a3 that the only text in the third listbox will contain

       a1_b1
       a3_b3

How can i do it ?

I trying to use the CollectionViewSource but i can’t define multi filter in this cases.

  • 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-26T07:37:34+00:00Added an answer on May 26, 2026 at 7:37 am

    In UI you will have to have the checkbox bound to something so that you are aware of the status of the checked items from both ListBoxes.

    Hence we bind it TwoWay to the ancestor ListBoxItem‘s IsSelected property. This way when checkboxes are checked they automatically register the checked item under ListBox.SelectedItems property.

    Based on this we perform multi binding ListBox3.ItemsSource to ListBox1.SelectedItems and ListBox2.SelectedItems. The multi value converter called MergeSelectedItemsHelper simply performs a union of the two selected items lists.

    I have used Array of TextBlock instead of List of SimpleClass to bind to all those ListBoxes.

    XAML:

       <StackPanel Orientation="Vertical">
    
            <StackPanel.Resources>
    
                <x:ArrayExtension x:Key="MyArraySource" Type="{x:Type TextBlock}">
                    <TextBlock Text="A" Tag="A1" DataContext="A_A1"/>
                    <TextBlock Text="B" Tag="B1" DataContext="B_B1"/>
                    <TextBlock Text="C" Tag="C1" DataContext="C_C1"/>
                    <TextBlock Text="D" Tag="D1" DataContext="D_D1"/>
                </x:ArrayExtension>
    
                <local:MergeSelectedItemsHelper 
                      x:Key="MergeSelectedItemsHelper"/>                
    
                <DataTemplate x:Key="ListBox1ItemTemplate">
                    <CheckBox 
                          IsChecked="{Binding IsSelected, 
                                      RelativeSource={RelativeSource 
                                                AncestorType={x:Type ListBoxItem}},
                                      Mode=TwoWay}"
                          Content="{Binding Text}"/>
                </DataTemplate>
                <DataTemplate x:Key="ListBox2ItemTemplate">
                    <CheckBox
                          IsChecked="{Binding IsSelected, 
                                      RelativeSource={RelativeSource 
                                                 AncestorType={x:Type ListBoxItem}},
                                      Mode=TwoWay}"
                          Content="{Binding Tag}"/>
                </DataTemplate>
    
            </StackPanel.Resources>
    
            <ListBox x:Name="ListBox1"
                     SelectionMode="Extended"
                     Margin="10"
                     ItemsSource="{StaticResource MyArraySource}"
                     ItemTemplate="{StaticResource ListBox1ItemTemplate}"
                     SelectionChanged="ListBox1_SelectionChanged">
            </ListBox>
    
            <ListBox x:Name="ListBox2"
                     SelectionMode="Extended"
                     Margin="10"
                     ItemsSource="{StaticResource MyArraySource}"
                     ItemTemplate="{StaticResource ListBox2ItemTemplate}"
                     SelectionChanged="ListBox1_SelectionChanged">
            </ListBox>
    
            <ListBox x:Name="ListBox3" Margin="10" DisplayMemberPath="DataContext">
                <ListBox.ItemsSource>
                    <MultiBinding Converter="{StaticResource MergeSelectedItemsHelper}">
                        <Binding Path="SelectedItems" ElementName="ListBox1"/>
                        <Binding Path="SelectedItems" ElementName="ListBox2"/>
                    </MultiBinding>
                </ListBox.ItemsSource>
            </ListBox>
        </StackPanel>
    </StackPanel>
    

    Code Behind:

    Now as ListBox.SelectedItems property is simply a non dependency property and also non-observable so the bindings will not automatically refresh. In code behind we will hage to refresh the binding when seletion is changed on the ListBox1 and ListBox2.

        private void ListBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var bndexp = BindingOperations.GetMultiBindingExpression(
                             ListBox3, ItemsControl.ItemsSourceProperty);
            if (bndexp != null)
            {
                bndexp.UpdateTarget();
            }
        }
    

    As said earlier, the multi value converter simply joins the selected items together and gets called when multi-binding is refreshed…

    public class MergeSelectedItemsHelper : IMultiValueConverter
    {
    
        #region IMultiValueConverter Members
    
        public object Convert(
               object[] values,
               Type targetType, 
               object parameter, 
               System.Globalization.CultureInfo culture)
        {
    
            var list1 = values[0] as IList;
            var list2 = values[1] as IList;
    
            var validList2 = list2 ?? new List<object>();
    
            return list1 != null
                     ? list1.Cast<object>().Union(validList2.Cast<object>())
                        : validList2.Cast<object>();
        }
    
        public object[] ConvertBack(
               object value,
               Type[] targetTypes,
               object parameter,
               System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

    Hope this helps.

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

Sidebar

Related Questions

I have a simple class as defined below: public class Person { int _id;
I have a simple class like this, import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Length; public class Form
given a string: msg=hello world How can I define this as a ctypes.c_void_p() data
In C++, if you define this function in header.hpp void incAndShow() { static int
I'm using a struct like this: define struct _Fragment{ int a; char *seq; }Fragment;
I'm stuck! I have this very simple test code and I can't get it
I define a simple Bug Class: using System; namespace BugNS.Entities { class Bug {
I cannot get this simple piece of code to compile without including the TestClass.cpp
Got this in char.h #ifndef _CHAR_H_ #define _CHAR_H_ #include <stdio.h> template <unsigned int TChar>
Consider this simple program. The program has two files: File Vehicle.java class Vehicle {

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.