【发布时间】:2014-04-08 20:14:00
【问题描述】:
我正在开发一个 WinRT 8.1 应用程序,并且我的自定义控件中有一个 MenuFlyout。本质上,当用户单击 MenuFlyout 中的项目时,用户将被导航到不同的页面。我的困境是我无法访问用户控件中的 Page 元素。有什么解决方法吗?我查看了许多类似的 SO 问题,但没有一个对我有用。
public sealed partial class BottomAppBar : UserControl {
public BottomAppBar() {
this.InitializeComponent();
//we are forced to manually add items as flyout does not support command
foreach (Vault v in User.Instance.Vaults) {
MenuFlyoutItem vault = new MenuFlyoutItem();
vault.Text = v.Name;
vault.Click += switchUser;
flyoutVault.Items.Add(vault);
}
}
private void switchUser(object sender, object e) {
//This line results in an error
this.Frame.Navigate(typeof(LoginPage));
/** Does not work as well
var parent = VisualTreeHelper.GetParent(this);
while (!(parent is Page)) {
parent = VisualTreeHelper.GetParent(parent);
}
(parent as Page).Frame.Navigate(typeof(LoginPage));
*/
}
【问题讨论】:
-
WPF 是指 WinRT/XAML,对吧?
标签: c# user-controls windows-runtime winrt-xaml mvvm-light