我的XAML文件包含以下内容:
<toolkit:ListPicker x:Name="lstSetups" Margin="0" VerticalAlignment="Top"
ItemsSource="{Binding BusRouteSetups}"
SelectedItem="{Binding SelectedSetup, Mode=TwoWay}"
Background="{StaticResource BackgroundBrush}" BorderBrush="{StaticResource AccentForegroundBrush}"
Foreground="{StaticResource AccentForegroundBrush}"
Header="{Binding LabelsResources.AreaSetup, Mode=OneWay, Source={StaticResource LocalizedLabels}}"
Template="{StaticResource ListPickerControlTemplate}"
ExpansionMode="FullScreenOnly"
FullModeItemTemplate="{StaticResource ChooseAreaDataTemplate}"
ItemTemplate="{StaticResource AreaSetupNormalDataTemplate}"/>
<phone:LongListSelector x:Name="lBusRoutes"
ItemsSource="{Binding SelectedSetupBusRoutes}"
SelectionChanged="lBusRoutes_SelectionChanged"
Grid.Row="1" Margin="0,12,0,0" ItemTemplate="{StaticResource BusRoutesDataTemplate}"/>
请注意,ListPicker具有与ViewModel中的SelectedSetup的双向绑定。 LongListSelector与View Model
中的SelectedSetupBusRoutes绑定ViewModel具有以下代码:
public Setup SelectedSetup
{
get
{
return _SelectedSetup;
}
set
{
if (_SelectedSetup != value)
{
_SelectedSetup = value;
NotifyPropertyChanged("SelectedSetup");
}
}
}
public ObservableCollection<Route> SelectedSetupBusRoutes
{
get
{
if (SelectedSetup != null)
{
return new ObservableCollection<Route>(SelectedSetup.Routes);
}
return null;
}
}
当我从更新ViewModel的ListPicker更改所选设置但它不会导致LongListSelector更新。如果您移出页面然后返回,它确实会更新。
我应该处理ListPicker更改事件并重新绑定LongListSelector,还是ViewModel可能会发生这种情况,但缺少某些内容?