wafers
wafers

Reputation: 1241

How two ItemSources can be bound to a ListBox item?

I have a case,

    public class dictLanguage
    {
        public string EnglishText { get; set; }
        public string FinnishText { get; set; }
    }

    IEnumerable<dictLanguage> result1 = from ....select new dictLanguage{ EnglishText=... };
    IEnumerable<dictLanguage> result2 = from ....select new dictLanguage{ FinnishText=... };

    LstBox.DataContext = result1

In Xaml, I have

<listbox ItemsSource="{Binding}">
  ...
  <TextBlock Text="{Binding EnglishText}">
  <TextBlock Text="{Binding FinnishText}">
  ...
</listbox>

I am reading English text from one xml file into "result1" and Finnish text from another xml file into "result2", but I can set only one ItemSource to ListBox. I have tried hard, but can't find out any solution. I want to display both values of "dictLanguage", which are being taken from two different XML files.

Looking for ANY solution,

Could anyone tell me the solution please? - Thanks!

Upvotes: 0

Views: 191

Answers (2)

KodeKreachor
KodeKreachor

Reputation: 8882

You could union your two lists together to create one items source:

IEnumerable<dictLanguage> result1;
IEnumerable<dictLanguage> result2;
//populate collections....
IEnumerable<dictLanguage> allResults = result1.Union(result2);

Upvotes: 1

Dmitry Reznik
Dmitry Reznik

Reputation: 6862

You can't bind two ItemsSources to a ListBox. Correct and easy way would be to combine data from 2 xml files into one object set (containing all translations). You can write:

from englishText in xml1
from finnishText in xml2
select new DictLanguage() { EnglishText = englishText, FinnishText = finnishText };

Please, read this link on more info for combining multiple sources.

Upvotes: 0

Related Questions