Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
namespace WpfApplication1.Gw
{
class ItemList
{
public byte[] Image { get; set; }
public string Title { get; set; }
}
}
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox Name="ListBox" Initialized="ListBox_OnInitialized">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Width="25"/>
<TextBlock VerticalAlignment="Center" Text="{Binding Title}"></TextBlock>
</StackPanel>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Windows;
using WpfApplication1.Gw;
using GW2NET;
using GW2NET.Common;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void ListBox_OnInitialized(object sender, EventArgs e)
{
var service = GW2.V2.Items.ForDefaultCulture();
var iconService = GW2.Rendering.RenderService;
IPageContext ctx = service.FindPage(pageSize: 10, pageIndex: 0);
var items = new List<ItemList>();
foreach (var page in service.FindAllPages(ctx.PageSize, ctx.PageCount))
{
foreach (var itemContent in page.Value)
{
byte[] png = iconService.GetImage(itemContent, "png");
items.Add(new ItemList() { Title = itemContent.Name, Image = png });
}
}
/**
Litle hardcoded old stuff
items.Add(new ItemList() { Title = "Learn C#", Image = "Images/Bandage.png" });
items.Add(new ItemList() { Title = "Wash the car", Image = "Images/Bandage.png" });
*/
ListBox.ItemsSource = items;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.