0

In my project I have something like this:

<ItemsControl ItemsSource="{Binding MyObservableCollection}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <View:MyView DataContext="{Binding}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

MyView of course has the data-binding to the locator, as usual in MVVM-Light:

DataContext="{Binding MyViewModelLocatorProperty, Source={StaticResource Locator}}"

ItemsControl has correctly created instances of MyView, but it did not appear to set the data-context (the data-context changed event was even raised). I've been struggling all day to find the problem & fix it and I've realized that the issue was those two data-context sets.

The way to fix this issue was to remove the data-context from MyView's XAML, but that's an ugly fix and it also means no blendability whatsoever. How can I solve this issue?

4

0 回答 0