[英]Windows Phone 8.1 ListView MenuFlyout: Can't open new Page with Frame.Navigate()
I want to open an Edit-page i've created when i click on the MenuFlyoutItem. 我想打开我在单击MenuFlyoutItem时创建的编辑页面。 Heres the code for my ListView: 继承我ListView的代码:
<ListView Name="ModelListXAML" Grid.Row="1" Margin="0,12,0,0" CanDragItems="True" SelectionChanged="ModelListXAML_SelectionChanged" ItemClick="ModelListXAML_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,5" Holding="ModellItem_Holding">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="ModellMenuEdit" Click="ModellMenuEdit_Click" Text="Bearbeiten"/>
<MenuFlyoutItem x:Name="ModellMenuDelete" Click="ModellMenuDelete_Click" Text="Löschen"/>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Margin="10, 0,0,0">
<TextBlock Text="{Binding name}" FontFamily="Segoe WP Semibold" FontSize="30" HorizontalAlignment="Left" Grid.Row="0"/>
<TextBlock Text="{Binding captions}" FontFamily="Segoe WP Semibold" FontSize="20" HorizontalAlignment="Left" Grid.Row="1" Foreground="Gray"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My Problem is, that the app crashes, when the ModellMenuEdit_Click event get's fired. 我的问题是,当ModellMenuEdit_Click事件被触发时,应用程序崩溃了。 Visual Studio gives me this Error: Visual Studio给我这个错误:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
And here's the Code for the ModelMenuEdit_Click event: 这是ModelMenuEdit_Click事件的代码:
private void ModellMenuEdit_Click(object sender, RoutedEventArgs e)
{
Modell datacontext = (e.OriginalSource as FrameworkElement).DataContext as Modell;
Frame.Navigate(typeof(ModellEdit));
}
Any idea how to solve this? 不知道怎么解决这个问题? Thank's for any response in advance :) 感谢提前做出任何回应:)
The problem is with the way you're trying to retrieve the DataContext. 问题在于您尝试检索DataContext的方式。 Try this: 尝试这个:
private void ModellMenuEdit_Click(object sender, RoutedEventArgs e)
{
var menuFlyoutItem = sender as MenuFlyoutItem;
Modell datacontext;
if (menuFlyoutItem != null)
{
datacontext = menuFlyoutItem.DataContext as Modell;
}
Frame.Navigate(typeof(ModellEdit), /*in case you want to pass datacontext*/ datacontext);
}
I've solved it! 我已经解决了! The actual problem was in the OnNavigatedTo() Method for the ModellEdit page :) 实际问题出现在ModellEdit页面的OnNavigatedTo()方法中:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.