问题描述
我有一个带有Pivot的页面。它基于Visual Studio模板。
I have a page with a Pivot. It´s based on the Visual Studio Template.
Pivot中有3个PivotItem。在第二个PivotItem上,我什么都没有。
There are 3 PivotItems in the Pivot. On the second PivotItem I have nothing in there.
我在CodeBehind中添加了事件SelectionChanged的处理。这很好。所以我可以通过代码捕获,当用户来到第二个PivotItem时。
I added in CodeBehind the handling for the event SelectionChanged. That works fine. So I can capture by code, when user comes to the second PivotItem.
现在出现了我的问题:当用户来到这个项目时,我想从WebService请求一些数据,转换数据填充LongListSelector中的数据。当发生一些错误时,我不想显示LongListSelector。在这种情况下,我想
显示一个带有消息的TextBox。
Now comes my problem: When user comes to this item, I want to request some data from an WebService, transform the data an populate the data in a LongListSelector. When some error occures, I want not to display the LongListSelector. In this case I want to show a TextBox with a message.
我怎样才能使这个工作?
How can I get this working?
推荐答案
Private Sub MainPivot_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles MainPivot.SelectionChanged
If MainPivot.SelectedIndex = 1 Then
Try
'Your code to get data from webservice
Dim client As New ServiceClient
Dim result As ObservableCollection(Of String) = client.GetDetailsAsync()
Dim lst As New LongListSelector
lst.ItemsSource = result
SecondPivotItem.Content = lst
'Your code to get data from webservice
Catch ex As Exception
'MessageBox.Show("Some error")
Dim txt As New TextBox
txt.AcceptsReturn = True
txt.TextWrapping = TextWrapping.Wrap
SecondPivotItem.Content = txt
End Try
End If
End Sub
这篇关于动态地向PivotItem添加内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!