Public Class DataInfo
Property title As String
Property description As String
Property link As String
End Class
Public NotInheritable Class MainPage
Inherits Page
要素の値を指定します。「description」プロパティに<description>要素の値を指定します。「link」プロパティに<link>要素の値を指定します。これらのプロパティの設定されたDataInfoをAddメソッドでリストであるmyDataInfoオブジェクトに追加します。
<p>ListBoxのItemsSourceプロパティにmyDataInfoオブジェクトを指定します。これで、「タイトル」と「概要」がListBox内に表示されます。</p>
<pre class="brush: plain; " type="syntaxhighlighter"><code class="hilightjs"> Protected Overrides Async Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
Dim myHttpClient As New HttpClient
Dim myUri As Uri = New Uri("http://www.microsoft.com/japan/msdn/rss/feed/rss.aspx", UriKind.Absolute)
Dim result = Await myHttpClient.GetStringAsync(myUri)
Dim xmldoc As XElement = XElement.Parse(result)
Dim myDataInfo As New List(Of DataInfo)
For Each myResult In From c In xmldoc.Descendants("item") Select c
With myDataInfo
.Add(New DataInfo With {.title = myResult.Element("title").Value, .description = myResult.Element("description").Value, .link = myResult.Element("link").Value})
End With
Next
ListBox1.ItemsSource = myDataInfo
End Sub
</code></pre>
<h4>ListBox内の項目が選択された時の処理</h4>
<p>ListBoxから選択された項目の、linkプロパティの値を変数myUrlに格納します。〔戻る〕ボタンの使用を可能にし、FameのNavigateメソッドで、myUrlを引数にWebViewPageに遷移します。</p>
<pre class="brush: plain; " type="syntaxhighlighter"><code class="hilightjs"> Private Sub ListBox1_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles ListBox1.SelectionChanged
myFrame.Visibility = Windows.UI.Xaml.Visibility.Visible
Dim myUrl = DirectCast(ListBox1.SelectedItem, DataInfo).link
backButton.IsEnabled = True
myFrame.Navigate(GetType(WebViewPage), myUrl)
End Sub
</code></pre>
<h4>〔戻る〕ボタンがクリックされた時の処理</h4>
<p>Frameコントロールを非表示にします。</p>
<pre class="brush: plain; " type="syntaxhighlighter"><code class="hilightjs"> Private Sub backButton_Click(sender As Object, e As RoutedEventArgs) Handles backButton.Click
myFrame.Visibility = Windows.UI.Xaml.Visibility.Collapsed
End Sub
End Class
</code></pre>
<div class="imagebox">
<a href="/sites/default/files/articles/376704.png" target="_blank"> <picture>
<source srcset="/sites/default/files/styles/picturize_mobile_1x/public/articles/376704.png.avif 1x, /sites/default/files/styles/picturize_mobile_2x/public/articles/376704.png.avif 2x" media="(max-width: 480px)" type="image/avif" width="480" height="289"/>
<source srcset="/sites/default/files/styles/picturize_normal_1x/public/articles/376704.png.avif 1x" media="(min-width: 480px)" type="image/avif" width="600" height="361"/>
<source srcset="/sites/default/files/styles/picturize_mobile_1x/public/articles/376704.png.webp 1x, /sites/default/files/styles/picturize_mobile_2x/public/articles/376704.png.webp 2x" media="(max-width: 480px)" type="image/webp" width="480" height="289"/>
<source srcset="/sites/default/files/styles/picturize_normal_1x/public/articles/376704.png.webp 1x" media="(min-width: 480px)" type="image/webp" width="600" height="361"/>
<source srcset="/sites/default/files/styles/picturize_normal_1x/public/articles/376704.png 1x" media="(min-width: 480px)" type="image/png" width="600" height="361"/>
<source srcset="/sites/default/files/styles/picturize_mobile_1x/public/articles/376704.png 1x, /sites/default/files/styles/picturize_mobile_2x/public/articles/376704.png 2x" media="(max-width: 480px)" type="image/png" width="480" height="289"/>
<img class="picturize-processed picturize-automatic picturize lazyload-auto lazyload-processed" width="600" height="361" src="/sites/default/files/styles/picturize_base/public/articles/376704.png" alt="" loading="lazy" typeof="foaf:Image" decoding="async">
</picture>
</a>
<div class="caption">図4:http://www.microsoft.com/japan/msdn/rss/feed/rss.aspx のRSSの構造一部。使用するのは、各<item>要素内の、<title><description><link>の3つの要素(クリックで拡大)</description>
Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
Dim myUrl = CStr(e.Parameter)
WebView1.Navigate(New Uri(myUrl, UriKind.Absolute))
End Sub
End Class