【发布时间】:2015-06-11 14:06:29
【问题描述】:
我有一个 GridView,我以编程方式将数据上下文设置为视图模型实例。 GridView 的 ItemsSource 绑定到一个可观察的集合 (PagesToRead),它是视图模型上的一个属性。
在 GridView.ItemTemplate 中,绑定与 ItemsSource 中的可观察集合相反,但我想将 StackPanel 的 Background 元素绑定到视图模型上的不同属性。
我正在寻找能够转义当前 ItemsSource 并绑定到视图模型上的 BackgroundColor 属性的魔法 <Background="{Binding Path=BackgroundColor, Source=???}">。
这是省略的 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>
【问题讨论】:
标签: c# xaml windows-runtime