2016-05-18 4 views
1

MenuFlyoutItemをクリックすると作成した編集ページを開きます。相続人は私のListViewのためのコード:Windows Phone 8.1 ListView MenuFlyout:Frame.Navigate()で新しいページを開くことができません

<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> 

私の問題は、ModellMenuEdit_Clickイベントが取得アプリのクラッシュは、解雇のこと、です。 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 

そしてここでは、コードはModelMenuEdit_Clickイベントのためだ:

private void ModellMenuEdit_Click(object sender, RoutedEventArgs e) 
    { 
     Modell datacontext = (e.OriginalSource as FrameworkElement).DataContext as Modell; 
     Frame.Navigate(typeof(ModellEdit)); 
    } 

これを解決する方法任意のアイデア?ありがとうございます。事前にお返事ありがとうございます:)

+0

正確な例外テキストを投稿してください。 'UnhandledException + =(sender、e)=>'の 'e'にカーソルを移動します。 – crea7or

答えて

0

問題は、あなたがDataContextを取得しようとしている方法にあります。試してみてください:

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); 
} 
0

私はそれを解決しました!実際の問題は、ModellEditページのOnNavigatedTo()メソッドにありました。

関連する問題