ListPicker shows object name instead of property's value

420 views Asked by At

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>

Code:

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;
}

When I try to select something in SourceAccountList it displays object name instead of its properties values. What am doing wrong? I found similar problem

ListPicker shows object name instead of property

But I'm doing the same thing.

3

There are 3 answers

0
A.K. On BEST ANSWER

You would have to Make the FullModeItemTemplate Like this

<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>
0
Oscar Emilio Perez Martinez On

List picker has two kinds of itemTemplate the "normal" that displays when you have when you have less than 5 items and the "Full Mode" that displays when you have more than 5.

to create a FullModeItemTemplate you should do something like this

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

The simplest solution is to override the ToString() method in the AccountModel class

public override string ToString()
{
    return this.AccountIban;
}