0

I have this MVVM project, and there an ObservableCollection. To that collection I store some information. Now, based on that info in the collection, I want to create "blocks" into my UI.

private ObservableCollection<Input> _inputlist;

public ObservableCollection<Input> iinputlist
{
    get
    {
        if (_inputlist == null)
        {
            _inputlist = new ObservableCollection<Input>();
        }
        return _inputlist;
    }
}

ObservableCollection works fine and I got there the info what I need. The information to the collection comes from external file (XML), which I read through. There could be few hundred "items" in it. I want to create one block for each item in the collection.

Now I have this XAML code:

<s:Toolbox x:Key="InputBlocks" ItemSize="80,75">
    <ListBox ItemTemplate="{Binding Source={StaticResource ItemsTemplate}}"
             ItemsSource="{Binding Source={StaticResource xml}, Path=iinputlist, UpdateSourceTrigger=PropertyChanged}">
    </ListBox>
</s:Toolbox>

Here I try to create those "blocks" inside a listbox, based on the information what's in the ObservableCollection. The ItemTemplate for the blocks works fine (tried with some hardcoded stuff).

For some reason, my GUI is not updated, and the blocks won't show in the listbox. With my understanding, ObservableCollection does include "OnPropertyChanged" in itself, so that shouldn't be a problem.

I also tried the binding with the following (replaced the listbox -part with this):

<ItemsControl.Items>
        <ItemsControl Name="inputit"
                      Style="{StaticResource ItemsTemplate}"
                      ItemsSource="{Binding Path=iinputlist, UpdateSourceTrigger=PropertyChanged}"/>
</ItemsControl.Items>

But still no update in GUI. What am I missing? I have a feeling, the problem has something to do with the binding, but I haven't figured out what's wrong. Thanks for the tips in advance.

0 Answers0