ListPicker没有';t显示对象列表
本文关键字:显示 对象 列表 没有 ListPicker | 更新日期: 2023-09-27 17:58:52
我创建了公共类"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>
我只想显示(银行的)名称。rest xaml代码:
<toolkit:ListPicker Header="Bank:" FullModeItemTemplate="{Binding lpkFullBank}"
ItemTemplate="{Binding lpkBank}" x:Name="ListPicker"
Margin="12,15,12,0" Height="110" VerticalAlignment="Top" />
现在,它只显示列表选择器中类的名称。我该怎么办?
如果你想从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>
我解决了它。我看到了我的错误。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>
现在一切正常。