ロジックコードを記述する

書き出されるXAMLコードはリスト1のようになります。

リスト1 編集されたXAMLコード(MainPage.xaml)

(1)areaTextBlockのTextWrappingプロパティにWrapを指定し、文字の回り込みを可能としています。
(2)最初の状態では、prevButtonとnextButtonのIsEnabledにはFalseが指定され、使用不可となっています。
<phone:PhoneApplicationPage 
  x:Class="WP7_GifWeatherService.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
  xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
  FontFamily="{StaticResource PhoneFontFamilyNormal}"
  FontSize="{StaticResource PhoneFontSizeNormal}"
  Foreground="{StaticResource PhoneForegroundBrush}"
  SupportedOrientations="Portrait" Orientation="Portrait"
  shell:SystemTray.IsVisible="True" Language="ja-JP">

  <!--LayoutRoot は、すべてのページ コンテンツが配置されるルート グリッドです-->
  <Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
 
    <!--TitlePanel は、アプリケーション名とページ タイトルを格納します-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
      <TextBlock x:Name="ApplicationTitle" Text="マイ アプリケーション" Style="{StaticResource PhoneTextNormalStyle}"/>
      <TextBlock x:Name="PageTitle" Text="天気予報" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>
 
    <!--ContentPanel - 追加コンテンツをここに入力します-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
      <TextBox Height="80" HorizontalAlignment="Left" Margin="96,87,0,0" Name="cityTextBox" VerticalAlignment="Top" Width="186" />
      <Button Content="実行" Height="80" HorizontalAlignment="Left" Margin="267,87,0,0" Name="goButton" VerticalAlignment="Top" Width="127" />
      <TextBlock Height="49" HorizontalAlignment="Left" Margin="46,102,0,0" Name="TextBlock1" Text="市" VerticalAlignment="Top" Width="44" FontSize="32" FontWeight="Bold" />
      <TextBlock Height="66" HorizontalAlignment="Left" Margin="12,15,0,0" Name="TextBlock2" Text="【例】例えば、[市]には松山市の場合は[松山]とだけ入力してください。" VerticalAlignment="Top" Width="438" TextWrapping="Wrap" Foreground="Crimson" />
      <TextBlock Height="76" HorizontalAlignment="Left" Margin="12,217,0,0" Name="areaTextBlock"  VerticalAlignment="Top" Width="438" FontSize="26" TextWrapping="Wrap" /> ■(1)
      <Image Height="129" HorizontalAlignment="Left" Margin="12,299,0,0" Name="Image1" Stretch="Uniform" VerticalAlignment="Top" Width="140" />
      <TextBlock Height="129" HorizontalAlignment="Left" Margin="171,299,0,0" Name="weatherTextBlock"  VerticalAlignment="Top" Width="279" FontSize="26" TextWrapping="Wrap" />
      <Button Content=">>" Height="83" HorizontalAlignment="Right" Margin="0,453,140,0" Name="nextButton" VerticalAlignment="Top" Width="95" IsEnabled="False" /> ■(2)
      <Button Content="<<" Height="83" HorizontalAlignment="Left" Margin="139,453,0,0" Name="prevButton" VerticalAlignment="Top" Width="95" IsEnabled="False" /> ■(2)
    </Grid>
  </Grid>
~コード略~
</phone:PhoneApplicationPage>

次に、MainPage.xamlを展開して表示されるMainPage.xaml.vbをダブルクリックして、リスト2のコードを記述します。

ロジックコードを記述する

リスト2 (MainPage.xaml.vb)

Option Strict On
Imports System.Xml.Linq

イメージを読み込んだり、操作したりする、コントロールやクラスの含まれる、基本の名前空間である、ImageToolsをインポートします。
Imports ImageTools
GIFのデコードとエンコードのクラスが含まれている、ImageTools.IO.Gif名前空間をインポートします。
Imports ImageTools.IO.Gif

Partial Public Class MainPage
  Inherits PhoneApplicationPage
 
  ' コンストラクター
  Public Sub New()
    InitializeComponent()
  End Sub
  Dim myId As Integer
  Dim cityId As String = String.Empty

文字列型のメンバ変数myNowにtodayという文字列を格納しておきます。
  Dim myNow As String = "today"
  Dim no As Integer = 0

[実行]ボタンがタップされた時の処理

[>>]ボタンの使用を可能にし、お天気情報を表示するDataShowプロシージャを実行します。
  Private Sub goButton_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles goButton.Click
    nextButton.IsEnabled = True
    DataShow()
  End Sub

人気記事トップ10

人気記事ランキングをもっと見る

企画広告も役立つ情報バッチリ! Sponsored

ClickHouse Cloudが実現した広告運用SaaS「ATOM」のデータ基盤革新、パフォーマンスを向上しながら、運用負荷とコストを削減 11月11日 6:20 AIで開発が加速する時代、品質保証はどう変わる? Tricentisが示すAIエージェント活用の実像 11月9日 6:45 悪用までの猶予が「1分」に迫るフロンティアAI時代に開発と本番を貫く脆弱性管理が必要 10月29日 8:30 欧州CRA対応とSBOM運用。AI生成コードのOSS混入問題の対策とは ――スニペット単位で検出する「FossID」「Insignary Clarity」によるSBOM運用 9月16日 6:40 PostgreSQLからTiDBへ、稼働中SaaSで進める段階的DB移行の実践と再設計への展望 9月7日 6:30 機能安全開発におけるGoogleTestの活用を支援!「Parasoft C/C++test CT」で実現する効率化&AI連携 4月14日 6:30 【CNDW2025】Grafanaが明かす「オブザーバビリティの哲学」ー最小限の労力で実用的なインサイトを得るには 1月23日 6:30 【CNDW2025】プロダクト急増に備える基盤刷新 ーウェルスナビがECSからEKSへの移行で得た知見とは 1月15日 6:30 【CNDW2025】250環境を5人で運用、構築時間は30分に ーKINTOテクノロジーズが語るインフラ基盤組織の作り方 2025年12月18日 6:30 新たな自動化で熱視線! AIエージェントの「推論能力」を支える2つのコンポーネントとは? 2025年11月28日 6:30