Hi,
ListView columns are filled as specified by the xaml. Each GridViewColumn of the GridView determines which data member is binded to the column by setting the DisplayMemberBinding property.
In the following link you will find a simple tutorial for ListViews:
http://tech.pro/tutorial/742/wpf-tutori ... iew-part-1
I will implement in NoesisGUI the last example shown there. The xaml would look something like this:
<Grid x:Class="ListViewTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Height="216" Width="435">
<StackPanel>
<ListView ItemsSource="{Binding GameCollection}">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Game Name"
DisplayMemberBinding="{Binding GameName}" />
<GridViewColumn Width="140" Header="Creator"
DisplayMemberBinding="{Binding Creator}" />
<GridViewColumn Width="140" Header="Publisher"
DisplayMemberBinding="{Binding Publisher}" />
</GridView>
</ListView.View>
</ListView>
<Button HorizontalAlignment="Right" Margin="5,5,5,5"
Content="Add Row" Click="AddRow_Click" />
</StackPanel>
</Grid>
Then we have to create the corresponding code-behind classes:
struct GameData : public Noesis::Core::BaseComponent
{
NsString gameName;
NsString creator;
NsString publisher;
GameData(const NsChar* n, const NsChar* c, const NsChar* p):
gameName(n), creator(c), publisher(p)
{
}
NS_REFLECTION_IMPLEMENT_INLINE(GameData, Noesis::Core::BaseComponent)
{
NsMeta<Noesis::Core::TypeId>("GameData");
NsProp("GameData", &GameData::gameData);
NsProp("Creator", &GameData::creator);
NsProp("Publisher", &GameData::publisher);
}
};
class ListViewTest : public Noesis::Gui::Grid
{
public:
ListViewTest(): mGameCollection(*new Collection())
{
Ptr<GameData> gameData = *new GameData("World Of Warcraft", "Blizzard", "Blizzard");
mGameCollection->Add(gameData.GetPtr());
gameData = *new GameData("Halo", "Bungie", "Microsoft");
mGameCollection->Add(gameData.GetPtr());
gameData = *new GameData("Gears Of War", "Epic", "Microsoft");
mGameCollection->Add(gameData.GetPtr());
}
Collection* GetGameCollection() const
{
return mGameCollection.GetPtr();
}
private:
void AddRow_Click(Noesis::Core::BaseComponent* sender, const RoutedEventArgs& e)
{
Ptr<GameData> gameData = *new GameData("A New Game", "A New Creator", "A New Publisher");
mGameCollection->Add(gameData.GetPtr());
}
private:
Ptr<Noesis::Gui::Collection*> mGameCollection;
NS_IMPLEMENT_REFLECTION_INLINE(ListViewTest, Noesis::Gui::Grid)
{
NsMeta<Noesis::Core::TypeId>("ListViewTest");
NsProp("GameCollection", &ListViewTest::GetGameCollection);
NsFunc("AddRow_Click", &ListViewTest::AddRow_Click);
}
};
And register the ListViewTest class so it can be created by the component factory when xaml is loaded:
extern "C" NS_DLL_EXPORT
void NsRegisterReflection(Noesis::Core::ComponentFactory* factory, NsBool registerComponents)
{
NS_REGISTER_COMPONENT(ListViewTest)
}
That's all
