ListPicker不显示对象列表

时间:2014-04-18 16:04:03

标签: c# xaml windows-phone-7

我创建了公共课“cBank”。这个班有

public string Name { get; set; }
public double first_session_in { get; set; }
public double second_session_in { get; set; }
public double third_session_in { get; set; }
public double first_session_out { get; set; }
public double second_session_out { get; set; }
public double third_session_out { get; set; }

我在ManiPage构造函数中创建了obj列表

List<cBank> oListBanks = new List<cBank>();
oListBanks.Add(new cBank {Name="Alior Bank", first_session_in = ...});
oListBanks.Add(new cBank {Name="Bank BPH",first_session_in=...});
this.ListPicker.ItemsSource = oListBanks;

我的xaml代码:

<phone:PhoneApplicationPage.Resources>
  <DataTemplate x:Name="lpkBank">
    <TextBlock Text="{Binding Name}" />
   </DataTemplate>
</phone:PhoneApplicationPage.Resources>

我想只显示姓名(银行)。休息xaml代码:

<toolkit:ListPicker Header="Bank:" FullModeItemTemplate="{Binding lpkFullBank}"
                    ItemTemplate="{Binding lpkBank}" x:Name="ListPicker" 
                    Margin="12,15,12,0" Height="110" VerticalAlignment="Top" />

现在它只显示列表选择器中的类名。我该怎么办?

2 个答案:

答案 0 :(得分:0)

如果您想从ListPicker显示,也可以像这样使用 在构造函数中:

List<cBank> oListBanks = new List<cBank>();
oListBanks.Add(new cBank {Name="Alior Bank", first_session_in = ...
oListBanks.Add(new cBank {Name="Bank BPH",first_session_in=...

并在您的XAML代码中:

 <phone:PhoneApplicationPage.Resources>
    <toolkit:ListPicker x:Key="ListPicker" ItemsSource="{Binding oListBanks , ElementName=this}" SelectionMode="Single">
     <toolkit:ListPicker.ItemTemplate>
      <DataTemplate>
       <TextBlock Text="{Binding Name}" />
      </DataTemplate>
     </toolkit:ListPicker.ItemTemplate>
    </toolkit:ListPicker>
 </phone:PhoneApplicationPage.Resources>

答案 1 :(得分:0)

我解决了。我看到了自己的错误。 Height="110"这就是列表没有下拉的原因之一。 这堂课是对的。

构造函数应如下所示:

List<cBank> oListBanks = new List<cBank>();
oListBanks.Add(new cBank {Name="Alior Bank", first_session_in = ...});
oListBanks.Add(new cBank {Name="Bank BPH",first_session_in=...});
...
this.ListPicker.ItemsSource = oListBanks;

XAML代码应为:

<toolkit:ListPicker x:Name="ListPicker" Header="Bank:" > 
              <toolkit:ListPicker.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Name}" FontSize="30" HorizontalAlignment="Center"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.ItemTemplate>
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Name}" Width="150"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>
        </toolkit:ListPicker>

现在一切正常。