1
我有兩個列表選取器。當第一個列表選擇器改變了選擇時,它應該過濾第二個列表選擇器的數據。 二ListPicker XAML是這樣在SelectionChanged上更新ListPicker
<TextBlock HorizontalAlignment="Left" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" Text="text" VerticalAlignment="Bottom"/>
<toolkit:ListPicker VerticalAlignment="Bottom" Name="CategoryList" ItemsSource="{Binding TransactionCategories, Mode=TwoWay}" SelectedItem="{Binding SelectedTransactionCategory, Mode=TwoWay}">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="Red" Width="24" Height="24"/>
<TextBlock Text="{Binding CategoryName,Mode=TwoWay}" Margin="12 0 0 0"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="16 21 0 20">
<Rectangle Width="43" Height="43"/>
<TextBlock Text="{Binding CategoryName, Mode=TwoWay}" Margin="16 0 0 0" FontSize="43" FontFamily="{StaticResource PhoneFontFamilyLight}" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
首先選擇器觸發事件GroupCategoryList_SelectionChanged
private void GroupCategoryList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var category = (TransactionGroupCategory) GroupCategoryList.SelectedItem;
((TransactionEditViewModel)DataContext).FilterCategoryByGroup(category.GroupCategoryId);
}
這是在視圖模型
public void FilterCategoryByGroup(int groupCategoryId)
{
TransactionCategories = ToObservableCollection(DatabaseBl.GetData<TransactionCategory>().Where(x => x.GroupCategoryId == groupCategoryId).OrderByDescending(tc => tc.TransactionCount));
if (TransactionCategories.Count > 0)
SelectedTransactionCategory = TransactionCategories[0];
}
一個梅託德第二個列表選擇器的UI從來沒有得到刷新,即使新數據是通過過濾方法獲取的。這可能是錯誤的。綁定問題可能?
我在視圖模型上的其他屬性設置爲NotifyPropertyChanged。我希望我不需要使用Observable集合那樣做。將盡力去做。 – nemke 2011-03-28 23:40:11
如果您只修改集合而不是替換集合,則不需要。一個可以真正絆倒人的小差異。 – 2011-03-28 23:44:11
那麼,我修改了實現NotifyPropertyChanged(「TransactionCategories」)的屬性public ObservableCollection TransactionCategories,它的工作原理:)感謝您的提示。 –
nemke
2011-03-28 23:46:36