ListView Code-Behind (C++)
Hello,
I am having a hard time implementing a code-behind for a ListView using the native sdk. Currently I'm searching for the ListView inside the XAML using FindName():
and then add elements to it using a collection:
This does work, however, it only adds items to the first column. Could you provide an example on how to code-behind a ListView with multiple columns using the native sdk and C++?
Thank you!
I am having a hard time implementing a code-behind for a ListView using the native sdk. Currently I'm searching for the ListView inside the XAML using FindName():
Code: Select all
lvServerBrowser = uiRoot->FindName<ListView>("lvServerBrowser");
Code: Select all
Noesis::Gui::Collection* collection = new Collection();
collection->Add("Item");
collection->Add("Item");
collection->Add("Item");
lvServerBrowser->SetItemsSource(collection);
Thank you!
Last edited by bandrewk on 06 Jun 2014, 07:35, edited 1 time in total.
-
sfernandez
Site Admin
- Posts: 3013
- Joined:
Re: ListView Code-Behind (C++)
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:
Then we have to create the corresponding code-behind classes:
And register the ListViewTest class so it can be created by the component factory when xaml is loaded:
That's all
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:
Code: Select all
<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>
Code: Select all
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);
}
};
Code: Select all
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);
}
};
Code: Select all
extern "C" NS_DLL_EXPORT
void NsRegisterReflection(Noesis::Core::ComponentFactory* factory, NsBool registerComponents)
{
NS_REGISTER_COMPONENT(ListViewTest)
}
Who is online
Users browsing this forum: No registered users and 2 guests