Listpicker:WP8正常工作,WP7不工作 [英] Listpicker: WP8 works fine, WP7 doesn't work

查看:71
本文介绍了Listpicker:WP8正常工作,WP7不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了一下,但找不到答案,如果后来道歉的话,我将不胜感激.

I searched but couldn't find that this had come up before, if it has then apologies and I'd appreciate a link.

我正在通用"应用程序,即我希望它能同时在7.5和8上运行.它具有一个列表选择器,可以选择您要用来代表体育新闻摘要的图像.在正常模式下,它仅显示图像名称,并显示实际图像 在其旁边的图像项中.在全屏模式下(我将其设置为始终扩展为全屏模式),它与图像一起显示名称.没什么了不起.

I'm making a "universal" app, i.e. I want it to work on both 7.5 and 8. It has a listpicker to select the image you want to use to represent a collection of sports feeds. In the normal mode it just shows the name of the image, with the actual image displayed in an Image item next to it. In the full mode (I set it to always expand to fullmode) it shows the name along with the image. Nothing amazing.

问题在于,当在WP8仿真器中运行时,它可以正常工作,但是在WP7(仿真器或我的设备)中运行时,无论是在标准模式还是完整模式下,绑定数据都不会出现.在普通模式下没有名称,在完整模式下没有名称或图像.但是你仍然可以 正确选择一个项目,然后您选择(但看不到)的项目将正确更新页面上的图像.

The issue is that when run in the WP8 emulator it works fine, but when run on WP7 (emulator or my device) the bound data doesn't appear, either in the standard or full mode. No names in the normal mode, no names or images in the full mode. But you can still select an item correctly, and the item that you selected (but couldn't see) will correctly update the Image on the page.

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace ListpickerTest
{
    public partial class MainPage : PhoneApplicationPage
    {
        List<ImageData> ImageList = new List<ImageData>()
                {
                    new ImageData(){ImagePath = "/Tiles/Default.png", Name = "Default"},
                    new ImageData(){ImagePath = "/Tiles/Gridiron.png", Name = "Gridiron"},
                    new ImageData(){ImagePath = "/Tiles/SoccerField.png", Name = "Pitch"},
                    new ImageData(){ImagePath = "/Tiles/BaseballDiamond.png", Name = "Diamond"}
                };
        
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.SportListPicker.ItemsSource = ImageList;
            DisplayImage.Source = new BitmapImage(new Uri("/Tiles/DefaultTile.png", UriKind.RelativeOrAbsolute));
        }

        private void SportListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ImageData data = ImageList.ElementAt(SportListPicker.SelectedIndex);

            DisplayImage.Source = new BitmapImage(new Uri(data.ImagePath, UriKind.RelativeOrAbsolute));
        }
    }
}

XAML:

<phone:PhoneApplicationPage 
    x:Class="ListpickerTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="False">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <toolkit:ListPicker Name="SportListPicker"
                                Margin="18,0,0,0"
                                FullModeHeader="Select a sport"
                                ExpansionMode="FullScreenOnly"
                                SelectionChanged="SportListPicker_SelectionChanged">

                <toolkit:ListPicker.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"
                                   HorizontalAlignment="Left" />
                    </DataTemplate>
                </toolkit:ListPicker.ItemTemplate>
                <toolkit:ListPicker.FullModeItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal"
                                    Height="230">
                            <Image Source="{Binding ImagePath}"
                                   Height="200"/>
                            <TextBlock Text="{Binding Name}"
                                       FontSize="36"
                                       VerticalAlignment="Center"
                                       Margin="30,0,0,0"/>
                        </StackPanel>
                    </DataTemplate>
                </toolkit:ListPicker.FullModeItemTemplate>
            </toolkit:ListPicker>

            <Image Name="DisplayImage"
                   Margin="0,0,0,200"
                   Height="140" />

        </Grid>
    </Grid>
 
</phone:PhoneApplicationPage>

我的ImageData类:

My ImageData class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ListpickerTest
{
    class ImageData
    {
        public string ImagePath { get; set; }
        public string Name { get; set; }
    }
}

这就是我所做的测试项目的全部代码.其他人是否也发现了同样的问题,或者有人可以在我的代码中看到问题?非常感谢您的帮助或建议.

That's the entirety of the code for the test project I made. Do others find this same issue, or can anyone see an issue in my code? Thanks very much for any help or suggestions.

推荐答案

你好

检查本文可能会有所帮助

check this article might be helpful

> http://www.windowsphonegeek.com/articles/listpicker-for-wp7-in -depth


这篇关于Listpicker:WP8正常工作,WP7不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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