快速的问题...在Button.Click上更改ListBox.ItemsSource绑定属性?
我有它的ItemsSource
属性ListBox
绑定到一个集合属性在视图模型像这样:
<ListBox Name="CollectionsListBox" ItemsSource="{Binding Activity.Timesheets}" />
我也有同样的视图中的两个Button
对象。问题是......我可以使用XAML将CollectionsListBox
ItemsSource Binding
从Activity.Timesheets
更改为Activity.Attachments
吗?
失败,从使用Command对象的视图模型?
编辑>>>
我发现了一个简单的解决方案通过使用RadioButton
!而非Button
期从霍华德的部分答案:
<ListBox Name="CollectionsListBox">
<ListBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=TimesheetsButton,Path=IsChecked}" Value="True">
<Setter Property="ListBox.ItemsSource" Value="{Binding Activity.Timesheets}" />
<Setter Property="ListBox.ItemContainerStyle" Value="{StaticResource TimesheetStyle}" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=AttachmentsButton,Path=IsChecked}" Value="True">
<Setter Property="ListBox.ItemsSource" Value="{Binding Activity.Attachments}" />
<Setter Property="ListBox.ItemContainerStyle" Value="{StaticResource AttachmentStyle}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.Style>
</ListBox>
的帮助非常感谢。
因为我绑定到视图模型,我就能够让你的实例的简化版本。非常感谢。 – Sheridan 2011-04-22 19:52:00
不客气。我只是觉得触发器有很多限制。也许我们可以有另一个问题在谈论这个问题。 – Howard 2011-04-23 02:24:33