사실 저는 Universal Windows Platform 용 C++/CX App을 작성하고 있습니다. 하나의 페이지 요소에서 다른 요소로 Windows 런타임 (예 : cv :: detail :: WaveCorrectKind 및 std :: string)의 일부가 아닌 다른 변수를 가진 클래스를 전달하려고합니다. 객체와 같은 Navigate 메소드에서 직접 전달하는 것은 불가능합니다. 외부 클래스에 작성하고 다른 페이지 요소에서 액세스 할 수있게 만들 수도 있습니다. 왜냐하면 다른 페이지 요소에서 액세스하기 위해 공개 섹션에서 일부 nonWinRT 변수 또는 클래스를 사용할 때마다 오류가 발생하기 때문입니다. 다음은 내가 갖고 싶은 예제 코드입니다. 페이지 1의UWP C++ App 페이지 간 OpenCV 관련 클래스 전달
머리글 :
//Page1.h
// Deklaration der Page1-Klasse
#pragma once
#include "Page1.g.h"
#include "Bibliothek.h"
namespace eigeneApp
{
[Windows::Foundation::Metadata::WebHostHidden]
public ref class Page1 sealed
{
public:
Page1();
protected:
//Navigations Events
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatingFrom(Windows::UI::Xaml::Navigation::NavigatingCancelEventArgs^ e) override;
private:
//Buttons Begin
void toPage2Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
//some other Buttonevents for capturing Photos and back to mainpage
//Buttons Ende
//A OpenCV related Element out of the Bibliothek.h
bibitem bibitemElement;
//Tasks that handle some stuff out of Bibliothek.h (photo processing) and capturing the photos asynchronous
// String Helper for Converting Platform::String to std::string and back
};
}
페이지 1의 CPP 파일 :
//
// Page1.xaml.cpp
// Implementing Page1-Klasse
//
#include "pch.h"
#include "Page1.xaml.h"
#include "Page2.xaml.h"
//other includes for asynch programming, Strings and so on...
#include "Bibliothek.h"
#include "opencv2\opencv.hpp"
#include "opencv2\imgproc.hpp"
#include "App.xaml.h"
using namespace eigeneApp;//and other using namespaces
Page1::Page1()
{
InitializeComponent();
}
//Buttons Start
void eigeneApp::Page1::toPage2Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() {
this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(Page2::typeid),bibitemElement);
}));
}
// other Button-functions are also here, but not relevant
//Tasks and the NavigationEvents are handled here and the String Helpers
지금까지 내가 알고있는 Bibliothek.h이 OpenCV의 관련 기능을 가진 클래스 (bibitem)를 포함
. Bibliothek.h의 코드는 게시 할 수 없습니다. 하지만 페이지 사이에 cv :: Mat를 전달하려고 시도했지만 작동하지 않았습니다.
또한 static bibitem이 포함 된 클래스를 작성하여 Page1과 Page2에서 사용하여 Page1에서 Page2로 콘텐츠를 가져 오려고했습니다.
#pragma once
#include "Bibliothek.h"
//NavigationData.h
class NavigationData
{
public:
static bibitem passingbibitem;
};
그리고 :
//NavigationData.cpp
#include "NavigationData.h"
#include "pch.h"
bibitem NavigationData::passingbibitem;
는 그 후 나는 페이지를 민간 부분의 각각에 NavigationData 요소를 추가하고이를 사용하려고 여기에 코드입니다. passingBibitem 함수는 Page1에서 사용할 수 있지만, Page2에 도착할 때 통과 함수의 데이터는 비어 있습니다. 따라서 내 정적은 동일하게 유지됩니다 ...
페이지간에 비 WinRT 클래스 및 변수를 전달하는 방법은 있습니까? 누군가가 저에게 어떻게 할 수 있는지 보여 줄 수 있습니까?
내 OnNavigatingFrom-Handler에서 bibitem-data를 기본값 값으로 설정하는 기능을 깜박했습니다. 이제는 별도의 클래스에있는 정적 항목과 함께 작동하는 것 같습니다. 누군가가 데이터를 전달 의 다른 방법을 알고있는 경우에, 여기에 게시 주시기
C++/CX는 C++의 엄격한 상위 집합입니다. 다른 C++ 객체를 통과하는 것처럼 객체를 전달하십시오. 정말로 멋진 것을 원한다면,'ref class'에서 감싸고 자원 관리를 무료로 받으십시오. 그러나 코드가 없으면 도움을 줄 수 없습니다. – IInspectable