Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LongListSelector+;所选项目-如何读取每个单独的属性?(WP8,Azure数据库)_C#_Sql_Azure_Windows Phone 8 - Fatal编程技术网

C# LongListSelector+;所选项目-如何读取每个单独的属性?(WP8,Azure数据库)

C# LongListSelector+;所选项目-如何读取每个单独的属性?(WP8,Azure数据库),c#,sql,azure,windows-phone-8,C#,Sql,Azure,Windows Phone 8,我有一个LongListSelector,用于存储来自Azure SQL数据库的数据 这是我的C代码: private async void RefreshTodoItemsToday() { try { coll = await todoTable .Where(todoItem => todoItem.TpEvt == "today") .ToCollect

我有一个LongListSelector,用于存储来自Azure SQL数据库的数据

这是我的C代码:

 private async void RefreshTodoItemsToday()
    {
        try
        {
            coll = await todoTable
                .Where(todoItem => todoItem.TpEvt == "today")
                .ToCollectionAsync();
        }
        catch (MobileServiceInvalidOperationException e)
        {
            MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK);
        }

        ListItemstoday.ItemsSource = coll;
    }
<phone:LongListSelector Name="ListItemsToday">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>

                                <TextBlock Name="TxtEvt" Text="{Binding Text}" TextWrapping="Wrap" Foreground="Gray" TextAlignment="Center" FontSize="30" Padding="30">
                                </TextBlock>

                        <Line X1="0" Y1="10" X2="240" Y2="10" Stroke="SkyBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="21"/>
                        </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>
var tmp1 = (TodoItem)ListItemsToday.SelectedItem; 
var tmp2 = tmp1.Id;
MessageBox.Show(tmp2.ToString());
这是我的XAML:

 private async void RefreshTodoItemsToday()
    {
        try
        {
            coll = await todoTable
                .Where(todoItem => todoItem.TpEvt == "today")
                .ToCollectionAsync();
        }
        catch (MobileServiceInvalidOperationException e)
        {
            MessageBox.Show(e.Message, "Error loading items", MessageBoxButton.OK);
        }

        ListItemstoday.ItemsSource = coll;
    }
<phone:LongListSelector Name="ListItemsToday">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>

                                <TextBlock Name="TxtEvt" Text="{Binding Text}" TextWrapping="Wrap" Foreground="Gray" TextAlignment="Center" FontSize="30" Padding="30">
                                </TextBlock>

                        <Line X1="0" Y1="10" X2="240" Y2="10" Stroke="SkyBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="21"/>
                        </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>
var tmp1 = (TodoItem)ListItemsToday.SelectedItem; 
var tmp2 = tmp1.Id;
MessageBox.Show(tmp2.ToString());
当我尝试强制转换此代码时,出现以下错误:

*System.NullReferenceException:对象引用未设置为对象的实例。 在Project.MainPage.ContextMenuRemove\单击(对象发送方,事件参数e)*

有人能帮我吗?
感谢您的朋友。

对更改的选择做出反应:

<phone:LongListSelector Name="ListItemsToday" SelectionChanged="ListItemsToday_SelectionChanged">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel>

                <TextBlock Name="TxtEvt" Text="{Binding Text}" TextWrapping="Wrap" Foreground="Gray" TextAlignment="Center" FontSize="30" Padding="30">
                </TextBlock>

                <Line X1="0" Y1="10" X2="240" Y2="10" Stroke="SkyBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="21"/>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
或对数据模板中的点击事件作出反应

<phone:LongListSelector Name="ListItemsToday" >
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel Tap="ListItemsToday_Tap">

                <TextBlock Name="TxtEvt" Text="{Binding Text}" TextWrapping="Wrap" Foreground="Gray" TextAlignment="Center" FontSize="30" Padding="30">
                </TextBlock>

                <Line X1="0" Y1="10" X2="240" Y2="10" Stroke="SkyBlue" HorizontalAlignment="Center" VerticalAlignment="Center" Height="21"/>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

Hi-igrali,是否可以获取LLS的选定ui项,我的意思是,如果我将网格作为数据模板,是否可以在selection changed事件中将网格作为选定项获取。