将多个源绑定到 ListView
我有一个带有 dataTemplate 的 ListView,我需要将其绑定到具有相同索引的 3 个不同源。我认为我必须完全在 XAML 中完成此操作,因为源(chart
)仅存在于 xaml 中。我正在使用 MVVM 模式。”
我已经写下了它“应该”如何工作,索引i
是公共密钥。
<ListView ItemsSource="{Binding ???}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<!-- Small rectangle filled with the same color as the corresponding line -->
<Rectangle
Height="10"
Width="10"
Fill="{Binding ElementName=chart, Path=Series[i].LineStroke}" />
<!-- The title of the corresponding line -->
<TextBlock
x:Name="Title"
Text="{Binding ElementName=chart, Path=Series[i].DataSeries.Title}" />
<!-- The actual value of the corresponding line on the current position-->
<TextBlock
x:Name="Value"
Text="{Binding ElementName=chart, Path=Behaviour.Behaviours[0].CurrentPoints[i].Y}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I have a ListView with a dataTemplate which I need to bind to 3 different sources with the same index. I think I have to do this completely in XAML, because the sources (chart
) only exists in xaml. I'm using the MVVM Pattern."
I have wrote down how it "should" work, the index i
is the common key.
<ListView ItemsSource="{Binding ???}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<!-- Small rectangle filled with the same color as the corresponding line -->
<Rectangle
Height="10"
Width="10"
Fill="{Binding ElementName=chart, Path=Series[i].LineStroke}" />
<!-- The title of the corresponding line -->
<TextBlock
x:Name="Title"
Text="{Binding ElementName=chart, Path=Series[i].DataSeries.Title}" />
<!-- The actual value of the corresponding line on the current position-->
<TextBlock
x:Name="Value"
Text="{Binding ElementName=chart, Path=Behaviour.Behaviours[0].CurrentPoints[i].Y}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,让我们看看。如何将列表视图绑定到
chart.Series
这样您就可以获得正确数量的元素。然后在数据模板中绑定该系列的属性。对于您可以使用 MultiBinding 和转换器来提取数据的行为现在您应该将图表和当前系列对象传递到您的转换器中,您应该能够在其中执行以下操作类似
var idx = Chart.Series.IndexOf(s)
这样您就可以访问行为中的相应点。Mh, lets see. How about you bind you listview to
chart.Series
this way you get the right number of elements. An then in your data template you bind the properties of the series. For the behaviour you could useMultiBinding
and a converter to extract the dataNow you should get the
chart
and the current series object passed into your converter where you should be able to do something likevar idx = chart.Series.IndexOf(s)
so you can access the corresponding point in the behaviours.