动态地向PivotItem添加内容 [英] Adding content to PivotItem dynamically

查看:116
本文介绍了动态地向PivotItem添加内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有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?

推荐答案

您可以编写如下代码

You can write code as below

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添加内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆