ListView sample (C++ SDK, 2.0.1f1)
Posted: 18 May 2017, 09:55
Hi,
Is there any sample showing how to use ListView using C++ SDK ?
Trying with the following codes but it doesn't work. Only blank control is shown:
I also wonder how the ListView::SetItemsSource can now the length of BaseComponent array past to it ? Did I miss something ?
Is there any sample showing how to use ListView using C++ SDK ?
Trying with the following codes but it doesn't work. Only blank control is shown:
Code: Select all
<ListView Margin="100,100,100,100" Grid.Column="0" Name="ListView">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding First}" FontWeight="Bold" />
<TextBlock Grid.Column="1" Text="{Binding Last}" FontWeight="Bold" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Code: Select all
NS_DECLARE_SYMBOL(First);
NS_DECLARE_SYMBOL(Last);
class DataModel : public INotifyPropertyChanged, public BaseComponent
{
public:
NS_IMPLEMENT_INTERFACE_FIXUP
public:
const NsChar* GetFirst() const
{
return _first.c_str();
}
void SetFirst(const NsChar* first)
{
if (_first != first)
{
_first = first;
_propertyChanged(this, NSS(First));
}
}
const NsChar* GetLast() const
{
return _last.c_str();
}
void SetLast(const NsChar* last)
{
if (_last != last)
{
_last = last;
_propertyChanged(this, NSS(Last));
}
}
PropertyChangedEventHandler& PropertyChanged()
{
return _propertyChanged;
}
// void Serialize(Noesis::Core::SerializationData* data) const
// {
// data->Serialize("First", _first);
// data->Serialize("Last", _last);
// }
//
// void Unserialize(Noesis::Core::UnserializationData* data, NsUInt32 version)
// {
// data->Unserialize("First", _first);
// data->Unserialize("Last", _last);
// }
private:
NsString _first = "First";
NsString _last = "Last";
PropertyChangedEventHandler _propertyChanged;
NS_IMPLEMENT_INLINE_REFLECTION(DataModel, BaseComponent)
{
NsMeta<TypeId>("DataModel");
NsImpl<INotifyPropertyChanged>();
NsProp("First", &DataModel::GetFirst, &DataModel::SetFirst);
NsProp("Last", &DataModel::GetLast, &DataModel::SetLast);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
extern "C" NS_DLL_EXPORT
void NsRegisterReflection(ComponentFactory* factory, NsBool registerComponents)
{
NS_REGISTER_COMPONENT(DataModel);
}
Code: Select all
static std::vector<DataModel> g_data(10);
auto listView(root->FindName<ListView>("ListView"));
listView->SetItemsSource(&g_data[0]);