Передающие параметры к Странице WPF через ее Uri

использовать SVN Revert

10
задан Joe White 29 August 2009 в 14:20
поделиться

1 ответ

Вы можете это сделать. См. http://www.paulstovell.com/wpf-navigation :

Хотя это не очевидно, вы можете передать данные строки запроса на страницу и извлеките его из пути. Например, ваша гиперссылка может передавать значение в URI:

 
 Go to page 2

When the page is loaded, it can extract the parameters via NavigationService.CurrentSource, which returns a Uri object. It can then examine the Uri to pull apart the values. However, I strongly recommend against this approach except in the most dire of circumstances.

A much better approach involves using the overload for NavigationService.Navigate that takes an object for the parameter. You can initialize the object yourself, for example:

Customer selectedCustomer = (Customer)listBox.SelectedItem;
this.NavigationService.Navigate(new CustomerDetailsPage(selectedCustomer));

This assumes the page constructor receives a Customer object as a parameter. This allows you to pass гораздо более богатая информация между страницами, и без синтаксического анализа строк.

17
ответ дан 3 December 2019 в 21:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: