📜 ⬆️ ⬇️

iOS vs WPF - tricky versus small

Friends, nothing cleverer than this headline, so there is a small background.
Like all programmers, I could not help but hear about the new language of Swift, to which various hello world trainers immediately fell down. However, seemingly simple applications are created (in my WPF-ny view) somehow too difficult, even after the introduction of a "simplified" language. Is it really necessary complexity or can they be created somehow simpler? I came across such an example of an iOS application (something like the application browser in appstore) and decided to create its full equivalent on the “native” WPF. The goal is to compare the complexity of the development and maybe someone will share a simpler method for iOS (if there is one). There won't be an abundance of screenshots, but the code - ... and the cat, in general, wept. So,

Task: show the list of applications from AppStore found by the specified filter. There should be an icon, title and price for each application. WPF'ny example is made absolutely identical to the original, up to the same jambs-delays when loading icons.

  1. We start Studio, we create WPF application - two mouse clicks + to give a name to the application.
  2. We connect to the references library Newtonsoft.Json.dll - it will help us to parse JSON
  3. We supplement the XAML code of the main form with our list of applications and the input field with a button at the top.
    Markup form
    <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>
    


    , — .
  4. SearchButton_Clicked F12 — , .
    C#
    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
        }
    }
    



    , , Swift , .
  5. ? F5! «angrybirds»:


    , : — , URL.


, 30 XAML + 44 C# . , .. - — , , async/await 4 .
, Swift-, — :


— , - « » (. « » ) — , XAML, C#.
— «» , 20 ( JSON- Apple, ). iOS — , , … , ? - — . , WPF/WinForms, Apple!

PS
— ; , , . !

UPD
, « », - - : « XXX ! YYY — -!». , :

Apple , ( Windows) - ( , ). ( ) , , -, Swift. , WPF ( TurboPascal + Turbo Vision!). WPF ( , ). WPF - — «», iOS .
WPF, . — , , , Apple , . !

')

Source: https://habr.com/ru/post/231439/


All Articles