使用SQL Server Compact在Windows Phone 8中的页面之间传递参数

吉恩·林(Gene Lim)

我试图将参数从主页传递到另一页,但是我不知道应该输入什么变量。举个例子

NavigationService.Navigate(new Uri("/ToDoDetailPage.xaml?detail" + **variable** , UriKind.Relative)); 

我正在使用SQL Server compact 3.5,我想选择数据并将其传递到另一页。什么应该替换该变量,因为现在它只是一个空变量。这是我已完成的代码:

MainPage.xaml.cs

namespace PhoneApp
{
public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();

        // Set the data context of the LongListSelector control to the sample data
        DataContext = App.ViewModel;

        // Sample code to localize the ApplicationBar
        //BuildLocalizedApplicationBar();
    }

    // Load data for the ViewModel Items
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (!App.ViewModel.IsDataLoaded)
        {
            App.ViewModel.LoadData();
        }

        using (DatabaseContext c = new DatabaseContext(DatabaseContext.ConnectionString))
        {
            c.CreateIfNotExists();
            c.LogDebug = true;
            //output todolist data from database
            MLongListSelector.ItemsSource = c.ToDoList.ToList();
        }
    }

    // Handle selection changed on LongListSelector
    private void MainLongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // If selected item is null (no selection) do nothing
        if (MLongListSelector.SelectedItem == null)
            return;

        // Navigate to the new page
        NavigationService.Navigate(new Uri("/ToDoDetailPage.xaml", UriKind.Relative));

        // Reset selected item to null (no selection)
        MLongListSelector.SelectedItem = null;
    }

   private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var si = MainLongListSelector.SelectedItem as PhoneApp.ViewModels.ItemViewModel;

        if (MainLongListSelector.SelectedItem == null)
            return;

        if (si.LineOne.Equals("+ To Do List"))
            NavigationService.Navigate(new Uri("/todolistPage.xaml", UriKind.Relative));
        else if (si.LineOne.Equals("+ Reminder"))
            NavigationService.Navigate(new Uri("/reminderPage.xaml", UriKind.Relative));

        // Reset selected item to null (no selection)(//important)
        MainLongListSelector.SelectedItem = null;
    }

}
}

MainPage.xaml

<phone:Pivot Title="MY APPLICATION">
        <!--Pivot item one-->
        <phone:PivotItem Header="today">
            <!--Double line list with text wrapping-->
            <phone:LongListSelector x:Name="MLongListSelector" Margin="0,0,-12,0" SelectionChanged="MainLongListSelector_SelectionChanged">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17">
                            <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                            <TextBlock Text="{Binding Description}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                        </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>
        </phone:PivotItem>



        <!--Pivot item two-->
        <phone:PivotItem Header="activities">
            <phone:LongListSelector x:Name="MainLongListSelector" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="LongListSelector_SelectionChanged">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17">
                            <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                            <TextBlock Text="Hello" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                        </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>
        </phone:PivotItem>

    </phone:Pivot>

下面是断点的图像

阿杰

您的意思是要将selected元素传递another page如果是这样,请尝试以下操作:

var select_Item = companyAppList.SelectedItem;
NavigationService.Navigate(new Uri("/PageName.xaml?Select_Item="+select_Item.Text, UriKind.Relative));

您可以像这样检索此参数:

if (NavigationContext.QueryString.ContainsKey("Select_Item"))
{
    TextBlock1.Text = NavigationContext.QueryString["Select_Item"];
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

数据通过WP8中的SQL Server Compact传递到另一个页面

如何使用Windows Phone 8连接到已经托管在服务器上的SQL Server数据库

什么是Windows Phone 7中的Sapi Server

将Windows Phone和Windows 8应用程序连接到SQL Server

在传递参数并导航到Windows Phone 8中的另一个页面时获取异常

我如何知道 Windows 中 Compact Os 使用的压缩算法?

SQL Server Compact与SQL Server和SQL Server Standard之间有什么区别?

Windows Phone 8:将数据从PHP页面传递到Windows Phone 8应用

创建Windows Phone 8应用并将其连接到数据库的最佳方法(最好是SQL Server)

页面之间的Windows Phone 8数据传输

如何使用静态库(Windows Phone 8)

在Windows Phone 8上使用Cookie

使用异步方法在Windows Phone 8.1中加载页面

连接到SQL Server Compact

使用Windows Phone 8应用程序访问html页面的选项卡中的html页面

在Windows Phone中的页面导航之间保存值

如何在Windows Phone 8中使用Telegram API?

在Windows Phone 8中使用WCF服务:异步方法?

无法在Windows Phone 8中使用SaveJpeg方法(NotSupportedException)

在Windows Phone 8中使用LongListSelector进行分页

如何在Windows Phone 8中通过边框使用按钮

如何在Windows Phone 8中使用TargetNullValue?

如何在Windows Phone 8.1中动态传递参数

Windows Phone 8记录

Windows Phone 8的LockScreen

Windows Phone 8中的NavigationDrawer

Windows Phone 8中的getrequeststream

在Windows Phone上使用WNS Silverlight 8.1-MPNS在Windows Phone 8上

HTML页面无法在Windows Phone 8中滚动