我正在构建基于位置的服务 Windows Phone 应用程序,这是我的第一个应用程序。我在使用 MVVM Light 时页面导航有困难。我正在关注Jesse Liberty 教程,到目前为止,当我在 FirstPage 中单击 ListBox 上的项目时,它可以导航到 SecondPage。
我想要做的是,用户在与我ListBox
的FirstPage
绑定中选择ListPicker
的SecondPage
. 因此用户可以轻松更改他们想要搜索的内容SecondPage
。
主页.xaml
<ListBox x:Name="MainMenu" ItemTemplate="{StaticResource MainMenu}" ItemsSource="{Binding Categories}" Margin="0,97,0,0">
<Custom:Interaction.Triggers>
<Custom:EventTrigger EventName="SelectionChanged">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding MainMenuCommand, Mode=OneWay}"/>
</Custom:EventTrigger>
</Custom:Interaction.Triggers>
</ListBox>
MainPage.xaml.cs
public MainPage()
{
InitializeComponent();
Messenger.Default.Register<CategoryModel>(this,c => NavigationService.Navigate(new Uri("/Views/VenueList.xaml", UriKind.Relative)));
}
主视图模型.cs
public MainViewModel()
{
MainMenuCommand = new RelayCommand<CategoryModel>((msg) => GoToVenueList(msg));
}
public RelayCommand<CategoryModel> MainMenuCommand
{
get;
private set;
}
private void GoToVenueList(CategoryModel msg)
{
Messenger.Default.Send(msg);
}
private CategoryModel _selectedItem;
public CategoryModel SelectedItem
{
get { return _selectedItem; }
set
{
if (_selectedItem == value)
{
return;
}
var oldValue = _selectedItem;
_selectedItem = value;
RaisePropertyChanged("SelectedItem", oldValue, value, true);
}
}
地点列表.xaml
<toolkit:ListPicker Margin="0,153,0,0" Background="{StaticResource PhoneAccentBrush}" VerticalAlignment="Top"
SelectedItem="{Binding Item, Mode=TwoWay}"
ItemsSource="{Binding Categories}"
ItemTemplate="{StaticResource CategorySelector}" FullModeHeader="Category" FullModeItemTemplate="{StaticResource FullCategorySelector}" BorderBrush="{StaticResource PhoneAccentBrush}" />
希望任何人都可以帮助我的问题。
场地列表视图模型
public VenueListViewModel()
{
Messenger.Default.Register<PropertyChangedMessage<CategoryModel>>(
this,
(action) => Item = action.NewValue
);
}
private CategoryModel _item;
public CategoryModel Item
{
get
{
return _item;
}
set
{
if (_item == value)
{
return;
}
_item = value;
// Update bindings, no broadcast
RaisePropertyChanged("Item");
}
}