는NullPointerException이 NavigationWindow에 돌아가는 후
<NavigationWindow x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="800" Width="600" Source="Page1.xaml">
이
<Page x:Class="WpfApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800"
Title="Page1" Name="IndexPage">
<ListView Name="myListView" ItemsSource="{Binding ElementName=IndexPage, Path=SeriesCollection}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" IsSynchronizedWithCurrentItem="True" SelectionChanged="handleSelected">
<ListView.ItemsPanel >
<ItemsPanelTemplate>
<WrapPanel>
</WrapPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel >
<Image Width="214" Height="317" Source="{Binding Image}"/>
<Label Content="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
페이지 2 단지 빈 해골
코드
namespace WpfApplication1
{
/// <summary>
/// Interaktionslogik für Page1.xaml
/// </summary>
public partial class Page1 : Page
{
private ObservableCollection<Series> _series =
new ObservableCollection<Series>();
public ObservableCollection<Series> SeriesCollection
{
get { return _series; }
}
public Page1()
{
InitializeComponent();
DirectoryInfo baseDir = new DirectoryInfo(@"C:\Serien");
DirectoryInfo[] dirs = baseDir.GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
Series serie = new Series(dir);
Console.WriteLine("adding " + serie.Name);
_series.Add(serie);
}
Console.WriteLine(_series.Count);
}
public void handleSelected(object sender, RoutedEventArgs args)
{
Series currentSerie = (Series) myListView.Items.CurrentItem;
Page2 page = new Page2();
this.NavigationService.Navigate(page);
Console.WriteLine(currentSerie.Name);
Console.WriteLine(currentSerie.GetType());
Console.WriteLine(currentSerie.ToString());
}
}
}
뒤에 욕실 내 PAGE1 이잖아 내 탐색 창 이잖아
그래서 SelectionChanged 이벤트를 트리거하여 SelectionChanged에서 처리하는 항목을 클릭하여 page2로 이동합니다 (지금까지는 그렇게 좋았습니다).
는 내가 탐색 창에서 뒤로 가기 (back) 버튼을 사용하고 난이 방법이 트리거 이유를 알고도 모릅니다
this.NavigationService.Navigate(page);
에서 NullPointerException이 함께 붙어 얻을. 그래서 obviosly 나는 바보 같은 짓을하고있다. Pls는 그것이 무엇인지에 관해 나에게 이야기한다. 시간과 노력에 감사드립니다.
다음 줄이 아닌 예외가 발생 했습니까? 'CurrentItem'과 그러므로'currentSerie'는'null' 일 수도 있습니다. – Clemens
@ 클레멘스는 VS2010이 말하고있는 것을 잘 설명합니다. 또한 콘솔 출력없이 실행하려고했는데 동일한 오류가 발생했습니다. – braunbaer
정확히 'null'이 무엇입니까? 스택 추적을 가지고 있습니까? – Clemens