Update ListPicker on SelectionChanged,监听ListPicker的selectItem的值变化【转】
I have two list pickers. When first list picker have selection changed it should filter data of second list picker. Second ListPicker xaml is like this
<TextBlockHorizontalAlignment="Left"Style="{StaticResource PhoneTextNormalStyle}"TextWrapping="Wrap"Text="text"VerticalAlignment="Bottom"/>
<toolkit:ListPickerVerticalAlignment="Bottom"Name="CategoryList"ItemsSource="{Binding TransactionCategories, Mode=TwoWay}"SelectedItem="{Binding SelectedTransactionCategory, Mode=TwoWay}">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanelOrientation="Horizontal">
<RectangleFill="Red"Width="24"Height="24"/>
<TextBlockText="{Binding CategoryName,Mode=TwoWay}"Margin="12 0 0 0"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanelOrientation="Horizontal"Margin="16 21 0 20">
<RectangleWidth="43"Height="43"/>
<TextBlockText="{Binding CategoryName, Mode=TwoWay}"Margin="16 0 0 0"FontSize="43"FontFamily="{StaticResource PhoneFontFamilyLight}"TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
First picker fires the event GroupCategoryList_SelectionChanged
privatevoidGroupCategoryList_SelectionChanged(object sender,SelectionChangedEventArgs e)
{
var category =(TransactionGroupCategory)GroupCategoryList.SelectedItem;
((TransactionEditViewModel)DataContext).FilterCategoryByGroup(category.GroupCategoryId);
}
This is a metod in ViewModel
public voidFilterCategoryByGroup(int groupCategoryId)
{
TransactionCategories=ToObservableCollection(DatabaseBl.GetData<TransactionCategory>().Where(x => x.GroupCategoryId== groupCategoryId).OrderByDescending(tc => tc.TransactionCount));
if(TransactionCategories.Count>0)
SelectedTransactionCategory=TransactionCategories[0];
}
The second list picker never get refreshed in UI, even though new data was fetched through filter method. What could be wrong with this.
原文地址:http://stackoverflow.com/questions/5466064/update-listpicker-on-selectionchanged