ListPicker显示对象名称而不是属性的值

时间:2013-12-10 13:13:26

标签: c# windows-phone-7 listpicker

XAML:

<toolkit:ListPicker Name="SourceAccountList" Width="680" FontSize="20" Height="50">
      <toolkit:ListPicker.ItemTemplate>
         <DataTemplate>
              <StackPanel>
                   <TextBlock Text="{Binding AccountIban}" />
              </StackPanel>
         </DataTemplate>
      </toolkit:ListPicker.ItemTemplate>
</toolkit:ListPicker>

代码:

public TransferInternal()
{
    InitializeComponent();

    Service1Client WCFClient = new ServiceReference1.Service1Client();
    WCFClient.GetSourceAccountIntenalListCompleted += new EventHandler<GetSourceAccountIntenalListCompletedEventArgs>(WCFClient_GetSourceAccountIntenalListCompleted);
    WCFClient.GetSourceAccountIntenalListAsync(GlobalVariables.ClientID);
}

void WCFClient_GetSourceAccountIntenalListCompleted(object sender, GetSourceAccountIntenalListCompletedEventArgs e)
{
    List<AccountModel> AccountList = new List<AccountModel>();

    foreach (var ListItem in e.Result)
    {
        AccountModel Account = new AccountModel();
        Account.AccountID = ListItem.AccountID;
        Account.AccountIban = ListItem.AccountIban;
        AccountList.Add(Account);
    }

    SourceAccountList.ItemsSource = AccountList;
}

当我尝试在SourceAccountList中选择某些内容时,它会显示对象名称而不是其属性值。怎么了?我发现了类似的问题

ListPicker shows object name instead of property

但我也在做同样的事情。

3 个答案:

答案 0 :(得分:0)

列表选择器有两种itemTemplate,当你有少于5个项目时显示“normal”,当你有超过5项时显示“Full Mode”。

创建一个FullModeItemTemplate你应该做这样的事情

   <toolkit:ListPicker.FullModeItemTemplate>
                        <DataTemplate>
                            <TextBlock FontSize="30" Text="{Binding AccountIban}"/>
                        </DataTemplate>
                    </toolkit:ListPicker.FullModeItemTemplate>

答案 1 :(得分:0)

你必须像这样制作FullModeItemTemplate

<toolkit:ListPicker Name="SourceAccountList" Width="680" FontSize="20" Height="50">
      <toolkit:ListPicker.ItemTemplate>
         <DataTemplate>
              <StackPanel>
                   <TextBlock Text="{Binding AccountIban}" />
              </StackPanel>
         </DataTemplate>
      </toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
         <DataTemplate>
              <StackPanel>
                   <TextBlock Text="{Binding AccountIban}" />
              </StackPanel>
         </DataTemplate>
      </toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>

答案 2 :(得分:0)

最简单的解决方案是覆盖AccountModel类

中的ToString()方法
public override string ToString()
{
    return this.AccountIban;
}