2016-08-27 131 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

當然是的......這就是我在**第二行**寫的。請考慮一下。我已經更新了我的答案,爲您提供了更多幫助。 –