快速的問題...在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