2013-01-03 43 views
0

好的我需要將此代碼中的標記傳遞給下一頁,但我不知道如何訪問它。有人可以幫助這個。將標記字段傳遞給其他視圖wf7

代碼:

<ListBox x:Name="AgendaList" Width="450" Height="520" Margin="10" SelectionChanged="event_SelectionChanged"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Horizontal"> 
          <Image Width="100" Stretch="Uniform" HorizontalAlignment="Center" Source="/SuperAgenda;component/Images/calendar.jpg" /> 
          <TextBlock Text="{Binding Title_}" Tag="{Binding EventId_}" /> 

         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

我用一個按鈕來送過來,所以我需要知道我怎麼可以在標籤數據獲取和擁有該按鈕將它發送到下一個頁面。 我的按鈕看起來是這樣,但它不發送數據:

private void viewEvent_Click(object sender, RoutedEventArgs e) 
    { 



     string uri = String.Format("/Views/Event_View/Event_View.xaml?id={0}", clickedLink.Tag); 
     NavigationService.Navigate(new Uri(uri, UriKind.Relative)); 

    } 

任何幫助將是不錯的感謝。

回答

0

其實,要在之間傳輸數據,你應該使用PhoneApplicationService類。

PhoneApplicationService.Current.State["field"] = someField; 

在您的按鈕點擊/點擊事件。

然後,你的下一個頁面上獲取該值使用投

someField = (fieldType)PhoneApplicationService.Current.State["field"]; 

這是你想要的嗎?

+0

好樣的。我需要將標籤的值發送到下一頁。基本上我需要知道選擇的事件ID並將它發送到下一頁以顯示該事件。 – Xintaris

0

只需使用您導航到的頁面的Navigation Context屬性即可。

if (this.NavigationContext.QueryString.ContainsKey("ProductId")) 
{ 
    productID = this.NavigationContext.QueryString["ProductId"]; 
} 
else 
{ 
    productID = App.Current.Resources["FeaturedProductID"].ToString(); 
} 
+0

感謝您的想法,但我不認爲它是我需要的。我只需要將標籤的值發送到下一頁。我從鏈接中檢查了這段代碼,它似乎不符合我的需要。 – Xintaris

+0

要獲得標籤值,只需執行以下操作: string tag =(string)this.NavigationContext.QueryString [「id」]; – paiden

+0

問題是我無法獲取標籤的值來發送它。它在哪裏是無法訪問的。如果我可以給textblock一個名稱,然後使用name.tag來獲取值,那將會很好。 – Xintaris

0

這裏使用Tag屬性是多餘的,因爲在綁定控件的DataTemplate包含你的對象的所有屬性。使用DataContext來檢索對象。添加Tap事件到StackPanelDataTemplate(這樣用戶可以點擊任何圖片或文字):

private void StackPanel_Tap(object sender, GestureEventArgs e) { 
    int eventid = ((sender as StackPanel).DataContext as MyObject).EventId_; 

    string uri = String.Format("/Views/Event_View/Event_View.xaml?id={0}", eventid); 
    NavigationService.Navigate(new Uri(uri, UriKind.Relative)); 
} 

然後使用NavigationContext在paiden的回答檢索recieving頁面上的價值。

+0

嘿,謝謝,看起來好像它可能工作。我現在正在測試它。 – Xintaris

相關問題