<Window x:Class="StoreBrowser.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="600" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display" UseLayoutRounding="True">
<DockPanel LastChildFill="True">
<DockPanel LastChildFill="True" DockPanel.Dock="Top">
<Button DockPanel.Dock="Right" Padding="10,5" Click="SearchButton_Clicked">Search</Button>
<TextBox Name="txtFilter"/>
</DockPanel>
<ListView Name="lstApps"><!-- -->
<ListView.ItemTemplate>
<DataTemplate><!-- -->
<DockPanel LastChildFill="True">
<Grid Width="70">
<Image DockPanel.Dock="Left" Source="{Binding artworkUrl60}" /><!-- - ! -->
</Grid>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding trackName}" FontWeight="Bold" FontSize="20" Padding="4"/>
<TextBlock Text="{Binding formattedPrice}" FontSize="16" Padding="4" />
<Rectangle Stroke="LightGray" Height="2" Width="250" HorizontalAlignment="Center" />
</StackPanel>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
</Window>
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
namespace StoreBrowser
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void SearchButton_Clicked(object sender, RoutedEventArgs e)
{
var filter = txtFilter.Text.Trim();//
if (string.IsNullOrEmpty(filter)) return;
filter = Uri.EscapeUriString(filter.Replace(' ', '+'));
using (var wc = new WebClient()) {
// JSON-
var res = JsonConvert.DeserializeObject<StoreReply>(wc.DownloadString(@"https://itunes.apple.com/search?media=software&term=" + filter));
lstApps.ItemsSource = res.results;//
}
}
}
class StoreReply
{
public int resultCount;
public List<AppInfo> results;//
}
class AppInfo
{ // - , .
public string trackName { get; set; }// title
public string formattedPrice { get; set; }// price
public string artworkUrl60 { get; set; }// icon
}
}
Source: https://habr.com/ru/post/231439/
All Articles