我参照一个官网的例子代码给语义缩放控件传递数据源,无法正常读取SemanticZoomLocation类中的Item值。
void ReadPage::OnNavigatedTo(NavigationEventArgs^ e)
{
cvs2->Source = safe_cast<PdfData^ >(e->Parameter)->Items;
safe_cast<ListViewBase^>(semanticZoom->ZoomedOutView)->ItemsSource = cvs2->View->CollectionGroups;
}
//
void ReadPage::semanticZoom_ViewChangeCompleted_1(Platform::Object^ sender, Windows::UI::Xaml::Controls::SemanticZoomViewChangedEventArgs^ e)
{
SemanticZoomLocation^ szl = e->SourceItem;
Object^ oj = safe_cast<Object^>(szl->Item);//此处oj显示无法读取内存。
}
而参照网格应用模板程序使用DefaultViewModel传入数据则可以正常读取SemanticZoomLocation类中的Item值。
void ReadPage::OnNavigatedTo(NavigationEventArgs^ e)
{
DefaultViewModel->Insert("Items",safe_cast<PdfData^ >(e->Parameter)->Items);
}
//
void ReadPage::semanticZoom_ViewChangeCompleted_1(Platform::Object^ sender, Windows::UI::Xaml::Controls::SemanticZoomViewChangedEventArgs^ e)
{
SemanticZoomLocation^ szl = e->SourceItem;
Object^ oj = safe_cast<Object^>(szl->Item);//此处oj可以正常显示我传入的数据的值。
}
其中数据源Items为property Windows::Foundation::Collections::IObservableVector<Platform::Object^>^ Items;
上述两种方法,ui上都可以正常显示我传入的数据,但是在获取Location值得时候结果却一个正常一个错误,
两者的区别在哪儿呢?