0

我有一个包含各种信息的客户列表。我有一个带有他们名字的列表框。当我选择一个条目时,我会在屏幕上看到有关客户的更多信息。当单击用户名及其更多信息时,我想“导航到”另一个屏幕。我不知道如何将有关条目的信息传递到下一个屏幕来完成此操作。

这是用户开始选择的列表框。

<ListBox x:Name="scheduleListBox" 
     ItemTemplate="{DynamicResource ItemTemplate}" 
     ItemsSource="{Binding Collection}" 
     Margin="8,8,8,0" 
     Style="{DynamicResource ListBox-Sketch}" 
     Height="154" 
     VerticalAlignment="Top"/>

这是可以单击以转到另一个屏幕的 TextBlock。它根据用户从 ListBox 中选择的内容进行更改。

<TextBlock Text="{Binding Customer}" 
     HorizontalAlignment="Left" 
     VerticalAlignment="Top" 
     Width="150" Margin="104,0,0,0"    
     Style="{DynamicResource BasicTextBlock-Sketch}">
     <i:Interaction.Triggers>
         <i:EventTrigger EventName="MouseLeftButtonDown">
             <pi:NavigateToScreenAction  TargetScreen="V02Screens.Customer_Status"/>
         </i:EventTrigger>
     </i:Interaction.Triggers>
</TextBlock>

我有点希望我可以在 Expression Blend 4 或 XAML 中做些什么。

4

2 回答 2

0

在 WPF 中,您可以为Navigate命令提供一个对象,该对象包含您想要的任何内容,包括您可能希望在下一页上显示的任何数据。然后在目标页面(您导航到的页面)上,您必须处理加载完成事件。

在您的第一页中,您可能会使用...导航

this.NavigationService.Navigate( somePage, someContainerObject );

然后你可以在 somePage 上检索它...

// Don't forget to subscribe to the event!
this.NavigationService.LoadCompleted += new LoadCompletedEventHandler(container_LoadCompleted);
...
void container_LoadCOmpleted( object sender, NavigationEventArgs e)
{
   if( e.ExtraData != null )
      // cast e.ExtraData and use it
}
于 2012-08-09T20:14:57.333 回答
0

在 Windows 8 中,您可以将整个对象传递给接收页面。

像这样:

// main page
private void ListBox_SelectionChanged_1
    (object sender, SelectionChangedEventArgs e)
{
    var _Item = (sender as ListBox).SelectedItem;
    Frame.Navigate(typeof(MainPage), _Item);
}

// detail page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    this.DataContext = e.Parameter;
}

在 WPF 和 SL 中,您可以在视图模型中保存对 SelectedItem 的引用。

// main page
private void ListBox_SelectionChanged_1
    (object sender, SelectionChangedEventArgs e)
{
    var _Item = (sender as ListBox).SelectedItem;
    MyModel.SelectedItem = _Item;
    // TODO: navigate
}

// detail page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    this.DataContext = MyModel.SelectedItem;
}

我希望这有帮助。

于 2012-08-09T17:35:26.787 回答