2016-08-27 182 views
0

您好我正在使用Visual Studio Enterprise并使用Prism.Unity.Forms和Xamarin.Forms进行开发。 在我的ViewModel我从web服务retrive我的数据(见该图) ViewModel with dataXamarin从列表视图加载列表视图

我想找回这些数据转化为我的视野下的ListView,但我不能访问ListaEstadoCuenta,我可以证明“polizaId”和“埃斯塔” 这是在信息‘ListaEstadoCuenta’ enter image description here

在我看来,我有ListView控件: enter image description here

请帮助我如何显示数据‘的标签ListaEstadoCuenta’名单,我希望你的帮助

+0

你怎么想表现出来?你也可以发布你的viewmodel? –

+0

您有一个标签,但是您的子列表中有多个数据。你想要显示哪些数据? – Jason

+0

我想显示muy子目录 – raranibar

回答

1

ListaEstadoCuenta是一个列表。这意味着您必须在标签的绑定中指定项目。例如。第一个项目:

<ViewCell> 
<!-- ... --> 
    <Label Text="{Binding ListaEstadoCuenta[0].Comprobante}" /> 
    <Label Text="{Binding ListaEstadoCuenta[0].FechaDoc}" /> 
<!-- ... --> 
</ViewCell> 

如果你想显示在一个标签列表中的项目,你必须使用转换器来组合值:

正值转换器

public class StringConcatenationConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     if (value is IEnumerable<EstadoCuentaDetalle>) 
     { 

      return string.Join(", ", ((IEnumerable<EstadoCuentaDetalle>)value).Select(x => x.Combrobante)); 
     } 
     return value; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

资源在你的页面上

你必须调整本地命名空间xmlns:local来引用你的程序集名称。

<ContentPage ... 
      xmlns:local="clr-namespace:FormsTest;assembly=FormsTest"> 
    <ContentPage.Resources> 
    <ResourceDictionary> 
     <local:StringConcatenationConverter x:Key="concatConverter"></local:StringConcatenationConverter> 
    </ResourceDictionary> 
    </ContentPage.Resources> 

绑定

<Label Text="{Binding ListaEstadoCuenta, Converter={x:StaticResource Key=concatConverter}}" /> 
+0

这个解决方案只显示我的第一个记录 – raranibar

+0

当然是的......这就是我在**第二行**写的。请考虑一下。我已经更新了我的答案,为您提供了更多帮助。 –