I’m trying to use a MultiBinding as the ItemsSource for a ListBox, and I want to bind a couple of collections to the MultiBinding. The collections aren’t populated until after the host control (a derivation of Page) has already been instantiated. Just after being constructed, I call a method that sets up some of the data for the Page, including these collections.
Right now, I have something like this:
public void Setup() { var items = MyObject.GetWithID(backingData.ID); // executes a db query to populate collection var relatedItems = OtherObject.GetWithID(backingData.ID); }
and I want to do something like this in XAML:
<Page ... ... <ListBox> <ListBox.ItemsSource> <MultiBinding Converter='{StaticResource converter}'> <Binding Source='{somehow get items}'/> <Binding Source='{somehow get relatedItems}'/> </MultiBinding> </ListBox.ItemsSource> </ListBox> ... </Page>
I know I can’t use DynamicResource in a Binding, so what can I do?
Sounds to me like what you really want is a CompositeCollection and to setup a DataContext for your Page.
The Code behind would look something like this:
Edit: I remembered that CollectionContainer doesn’t participate in the logical tree so you need to use a CollectionViewSource and a StaticResource.