2016-12-15 2 views
0

ich eine Klasse zu implementieren versucht, die here als ItemSource für ListView folgende Microsoft-Dokumentation gesetzt werden kann heißt IObservableVector<T> Umsetzung aber wie immer, Dokumentation funktioniert nie und es gibt keine C++ Beispielcode zu beginnen. Der Inhalt meiner XAML für Mainpage ist nurrichtig implementieren ItemSource für Listview

<ListView x:Name="TestListView"/> 

und der Quellcode

public ref class MyStringSrc sealed : Windows::Foundation::Collections::IObservableVector<Platform::String^> 
{ 
public: 
    // Inherited via IVector 
    virtual Windows::Foundation::Collections::IIterator<Platform::String ^>^First(); 

    // Inherited via IObservableVector 
    virtual property unsigned int Size 
    { 
     unsigned int get() 
     { 
      return _size; 
     } 
    } 
    virtual Platform::String^GetAt(unsigned int index); 
    virtual Windows::Foundation::Collections::IVectorView<Platform::String ^>^GetView(); 
    virtual bool IndexOf(Platform::String ^value, unsigned int *index); 
    virtual void SetAt(unsigned int index, Platform::String ^value); 
    virtual void InsertAt(unsigned int index, Platform::String ^value); 
    virtual void RemoveAt(unsigned int index); 
    virtual void Append(Platform::String ^value); 
    virtual void RemoveAtEnd(); 
    virtual void Clear(); 
    virtual unsigned int GetMany(unsigned int startIndex, Platform::WriteOnlyArray<Platform::String ^, 1U> ^items); 
    virtual void ReplaceAll(const Platform::Array<Platform::String ^, 1U> ^items); 
    virtual event Windows::Foundation::Collections::VectorChangedEventHandler<Platform::String ^>^VectorChanged; 
private: 
    unsigned int _size = 1000; 
}; 

public ref class MainPage sealed 
{ 
public: 
    MainPage(); 
}; 
MainPage::MainPage() 
{ 
    InitializeComponent(); 
    TestListView->ItemsSource = ref new MyStringSrc(); 
} 

Windows::Foundation::Collections::IIterator<Platform::String ^>^MyStringSrc::First() 
{ 
    throw ref new Platform::NotImplementedException(); 
    // TODO: insert return statement here 
} 

Platform::String^MyStringSrc::GetAt(unsigned int index) 
{ 
    throw ref new Platform::NotImplementedException(); 
    // TODO: insert return statement here 
} 

Windows::Foundation::Collections::IVectorView<Platform::String ^>^MyStringSrc::GetView() 
{ 
    throw ref new Platform::NotImplementedException(); 
    // TODO: insert return statement here 
} 

bool MyStringSrc::IndexOf(Platform::String ^value, unsigned int *index) 
{ 
    return false; 
} 

void MyStringSrc::SetAt(unsigned int index, Platform::String ^value) 
{ 
    throw ref new Platform::NotImplementedException(); 
} 

void MyStringSrc::InsertAt(unsigned int index, Platform::String ^value) 
{ 
    throw ref new Platform::NotImplementedException(); 
} 

void MyStringSrc::RemoveAt(unsigned int index) 
{ 
    throw ref new Platform::NotImplementedException(); 
} 

void MyStringSrc::Append(Platform::String ^value) 
{ 
    throw ref new Platform::NotImplementedException(); 
} 

void MyStringSrc::RemoveAtEnd() 
{ 
    throw ref new Platform::NotImplementedException(); 
} 

void MyStringSrc::Clear() 
{ 
    throw ref new Platform::NotImplementedException(); 
} 

unsigned int MyStringSrc::GetMany(unsigned int startIndex, Platform::WriteOnlyArray<Platform::String ^, 1U> ^items) 
{ 
    return 0; 
} 

void MyStringSrc::ReplaceAll(const Platform::Array<Platform::String ^, 1U> ^items) 
{ 
    throw ref new Platform::NotImplementedException(); 
} 

Wenn die App läuft, habe ich immer

Microsoft C++ Ausnahme: Plattform :: InvalidArgumentException^auf Speicherplatz 0x02E2DA80. HRESULT: 0x80070057 Der Parameter ist falsch. WinRT-Information: Der Parameter ist falsch.

direkt an der Linie, wo ich

TestListView->ItemsSource = ref new MyStringSrc(); 

gesetzt Gibt es eine Beispielimplementierung ich folgen kann?

+0

Benötigen Sie speziell eine benutzerdefinierte IObservableVector-Klasse, anstatt etwas wie [Vector] (https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh441570.aspx) zu verwenden? –

+0

@DecadeMoon Ich weiß es eigentlich nicht. Ich versuche, inkrementelles Laden durchzuführen, wie in dem Artikel, der vorschlägt, "IObservableVector" zu implementieren. –

Antwort

0

Im Gegensatz zu der Dokumentation, müssen Sie NICHT implementieren IObservableVector. Was Sie implementieren müssen, ist Windows::UI::Xaml::Interop::IBindableObservableVector. Ich fand das in dem Windows 8.1 XAML-Beispiel in dem Artikel verweist. (Die Dokumentation bezieht sich auf den Gott verlassen Windows 8.1!) Leider werde ich alle meine generischen Code verlieren. Sollte nicht mit generic gestartet werden, wenn es um UI geht.

Microsoft-Dokumentation, wie immer, fehlt immer die nötige Klarheit. Es sagt nie, welche Art von Ding als ItemsSource eingestellt werden kann. Durch Experimente scheint es, dass es etwas unter dem Regenschirm sein muss.

Verwandte Themen