2

我正在制作一个页面,其中包含一个ViewPager包含TextView显示标题和ListView显示我制作的自定义视图中的一些图表的页面。

我在 WP7 中运行良好,代码如下:

<controls:Pivot Title="Stakeholder">
    <controls:PivotItem Header="Last hour">
        <ScrollViewer>
            <ItemsControl ItemsSource="{Binding Locations}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="{Binding Name}" HorizontalAlignment="Center" />
                            <chart:MiniChartHour MinMaxRange="{Binding ChartHourRange}" Data="{Binding ChartHourSamples}" Margin="0,0,0,15" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </controls:PivotItem>

    <!--Pivot item last day-->
    <controls:PivotItem Header="Last day">
        <ScrollViewer>
            <ItemsControl ItemsSource="{Binding Locations}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="{Binding Name}" HorizontalAlignment="Center" />
                            <chart:MiniChartDay MinMaxRange="{Binding ChartDayRange}" Data="{Binding ChartDaySamples}" Margin="0,0,0,15" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </controls:PivotItem>
    ...
    More of these here
    ...
</controls:Pivot>

然而,在 WP7 上,它使用了一个Pivot控件,类似于ViewPagerandroid 中的控件。该Locations属性是a ObservableCollection,它拥有LocationViewModels。每个LocationViewModels 都有 4 个不同图表的范围和数据,每个图表显示不同的数据粒度。在上面的代码中,这个Locations属性被绑定了几次,没有任何问题。但是,当我想在 Android 上做类似的事情时,会SwissBindings不止一次地发出很多关于 Path 的警告。我在 Android 上的 View 代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res/BK.EMS.Stakeholder.UI.Droid.vNext"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <TextView
    android:id="@+id/chartHeader"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:textAppearance="?android:attr/textAppearanceLarge"
    local:MvxBind="Text Name"
    />

  <RelativeLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <Mvx.MvxBindableListView 
      android:id="@+id/chartListHour"
      android:layout_height="fill_parent"
      android:layout_width="fill_parent"
      android:cacheColorHint="#00000000"
      android:listSelector="#00000000"
      android:orientation="vertical"
      local:MvxItemTemplate="@layout/chartdetailhour"
      local:MvxBind="ItemSource Locations, Visibility IsHourVisible,Converter=Visibility"
      />

    <Mvx.MvxBindableListView
      android:id="@+id/chartListDay"
      android:layout_height="fill_parent"
      android:layout_width="fill_parent"
      android:cacheColorHint="#00000000"
      android:listSelector="#00000000"
      android:orientation="vertical"
      local:MvxItemTemplate="@layout/chartdetailday"
      local:MvxBind="ItemSource Locations, Visibility IsDayVisible,Converter=Visibility"
      />
    ...
    More of the BindableListViews here
    ...
  </RelativeLayout>
</FrameLayout>

我得到的例外是:

Problem parsing Swiss binding MvxException: You cannot specify Path more than once - first Path 'Locations', second Path 'Visibility IsHourVisible', position 50 in ItemSource Locations, Visibility IsHourVisible,Converter=Visibility
at Cirrious.MvvmCross.Binding.Parse.Binding.Swiss.MvxSwissBindingParser.ParseNextBindingDescriptionOptionInto (Cirrious.MvvmCross.Binding.Interfaces.Parse.MvxSerializableBindingDescription description) [0x00000] in <filename unknown>:0 
at Cirrious.MvvmCross.Binding.Parse.Binding.Swiss.MvxSwissBindingParser.ParseBindingDescription () [0x00000] in <filename unknown>:0 
at Cirrious.MvvmCross.Binding.Parse.Binding.Swiss.MvxSwissBindingParser.ParseTargetPropertyNameAndDescription () [0x00000] in <filename unknown>:0 
at Cirrious.MvvmCross.Binding.Parse.Binding.Swiss.MvxSwissBindingParser.TryParseBindingSpecification (System.String text, Cirrious.MvvmCross.Binding.Interfaces.Parse.MvxSerializableBindingSpecification& requestedBindings) [0x00000] in <filename unknown>:0 
4

1 回答 1

4

你应该使用“;” 而不是 "," 来添加多个绑定描述。

local:MvxBind="ItemSource Locations; Visibility IsDayVisible,Converter=Visibility"

应该管用 :-)

于 2013-04-05T12:13:25.977 回答