正确实现listView的项目库
Properly implement ItemSource for ListView
我尝试实现一个可以将其作为ItemSource
作为ListView
的类实现,此处是Microsoft文档,即实现IObservableVector<T>
,但与往常一样,文档永远无法使用,并且没有C 示例代码。我的主页的XAML内容只是
<ListView x:Name="TestListView"/>
和源代码
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();
}
运行应用程序时,我总是得到
Microsoft C 异常:Platform :: InvalidArgumentException ^在存储位置0x02E2DA80。Hresult:0x80070057参数不正确。winrt信息:参数不正确。
就在我设置的线上
TestListView->ItemsSource = ref new MyStringSrc();
我可以遵循样本实现吗?
与文档相反,您不得实现 IObservableVector
。您必须实现的是Windows::UI::Xaml::Interop::IBindableObservableVector
。我在Windows 8.1 XAML样本中发现了这一点,这是文章中的。(文档是指神遗弃的Windows 8.1!)不幸的是,我将失去所有通用代码。无论如何,不应该从通用开始。
Microsoft的文档像往常一样,总是缺乏必要的清晰度。它永远不会说出可以将哪种类型设置为ItemsSource
。通过实验,看来它必须是Windows::UI::Xaml::Interop::IBindable*
伞下的东西。
相关文章:
- 如何使QML ListView部分围绕项目
- 使用 QSortFilterProxyModel 对 Qml ListView 的数据进行排序
- 对 Eclipse 项目库的更改将还原给团队的其他成员
- 以编程方式为 ListView 的项生成 UI
- 如何异步更新ListModel和ListView
- 从QML ListView中QABStractListModel中的数据操纵数据
- QML ListView将新行添加到模型中的子向量
- QT QML ListView布局未调整大小
- Qt ListView 不显示C++模型内容
- Qt/QML:将 WebEngineView 放在 ListView 中并调用 loadHtml()
- 使用QQMLContext访问嵌套ListView
- 如何在 CLion 中正确添加项目库
- 如何从 ListModel 中选择单个 ListElement 并在 ListView 中处理它
- 正确实现listView的项目库
- Borland C++ ListView Error
- 如何使Windows ListView控件和它们映射到的对象保持同步
- QML ListView计数为零,并且只有一些行可见
- C++ Windows API - 如何使用ListView的默认WIndows Proc?
- 使用 QList<QObject*> 作为模型的 QML ListView
- 如何禁用ListView选择视觉效果并绘制项目周围的矩形