【问题标题】:ListPicker shows object name instead of property's valueListPicker 显示对象名称而不是属性值
【发布时间】:2013-12-10 13:13:26
【问题描述】:

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

但我也在做同样的事情。

【问题讨论】:

    标签: c# windows-phone-7 listpicker


    【解决方案1】:

    您必须像这样制作 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】:

      列表选择器有两种 itemTemplate,当您拥有少于 5 个项目时显示的“正常”和当您拥有超过 5 个项目时显示的“完整模式”。

      要创建 FullModeItemTemplate 你应该这样做

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

      【讨论】:

        【解决方案3】:

        最简单的解决方案是覆盖AccountModel类中的ToString()方法

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-03-31
          • 1970-01-01
          • 1970-01-01
          • 2018-07-21
          • 1970-01-01
          • 2019-05-22
          • 2016-07-21
          相关资源
          最近更新 更多