I have a GridView for which I programmatically set the data context to the view model instance. The GridView ItemsSource is bound to the observed collection (PagesToRead), which is a property in the view model.
In GridView.ItemTemplate, the binding goes against the observed collection in the ItemsSource , but I want to bind the StackPanel Background element to another property in the view model.
I am looking for magic <Background="{Binding Path=BackgroundColor, Source=???}">that will exit the current ItemsSource and bind to the BackgroundColor property in the view model.
Here's the skipped XAML:
<Grid>
<GridView x:Name="MainGrid" CanReorderItems="True" CanDragItems="True"
ItemsSource="{Binding Path=PagesToRead}"
<GridView.ItemTemplate>
<DataTemplate >
<StackPanel>
<Background="{Binding Path=BackgroundColor, Source=???}">
<TextBlock Text="{Binding Path=Title}"
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
source
share