我有一个GridView为此我编程方式设置数据上下文视图模型实例。 GridView的ItemsSource绑定到一个观察集合(PagesToRead),这是在视图模型的属性。
内GridView.ItemTemplate,结合顶在的ItemsSource观察集合,但我想给的StackPanel的背景元素绑定到视图模型不同的属性。
我正在寻找的魔术<Background="{Binding Path=BackgroundColor, Source=???}">
将退出当前的ItemsSource和绑定到视图模型backgroundColor属性。
这里的消隐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>