2011-04-01 4 views
0

동일한 인덱스를 가진 3 개의 다른 소스에 바인딩해야하는 dataTemplate이있는 ListView가 있습니다. 소스 (chart)는 xaml에만 있기 때문에 XAML에서 완전히이 작업을 수행해야한다고 생각합니다. 나는 MVVM 패턴을 사용하고 있습니다.해야 "작품은, 인덱스 i 공통 핵심"나는 그것이 어떻게 기록한 한
".여러 소스를 ListView에 바인딩

<ListView ItemsSource="{Binding ???}"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
     <StackPanel> 
      <!-- Small rectangle filled with the same color as the corresponding line --> 
      <Rectangle 
       Height="10" 
       Width="10" 
       Fill="{Binding ElementName=chart, Path=Series[i].LineStroke}" /> 
      <!-- The title of the corresponding line --> 
      <TextBlock 
       x:Name="Title" 
       Text="{Binding ElementName=chart, Path=Series[i].DataSeries.Title}" /> 
      <!-- The actual value of the corresponding line on the current position--> 
      <TextBlock 
       x:Name="Value" 
       Text="{Binding ElementName=chart, Path=Behaviour.Behaviours[0].CurrentPoints[i].Y}" /> 
     </StackPanel> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 
+0

MVVM을 사용하고 있습니다.이 경우 ** ViewModel **을 생성하면 안됩니까? Series와 Behavior를 모두 포함하는 클래스. 그런 다음이 ViewModel을 ListView의 바인딩 소스로 사용하십시오. – Damb

+0

나는 차트 컨트롤에 대한 데이터 만 제공하는 ViewModel을 가지고 있지만 차트는 색상을 만들고 차트 만 현재 선택된 Y- 포인트를 알고 있습니다. 차트는 뷰에서만 알 수 있습니다. – chriszero

답변

2

니켈 수소, 볼 수 있습니다. 당신이 바인딩에 대해 당신이 chart.Series로 목록보기 방법 이 방법은 요소의 오른쪽 번호를. 다음 데이터 템플릿에이 시리즈의 속성을 바인딩합니다. 이제을 ​​받아야하면 데이터

<ListView ItemsSource="{Binding Path=Series, ElementName=chart}"> 
<ListView.ItemTemplate> 
    <DataTemplate> 
    <StackPanel> 
     <!-- Small rectangle filled with the same color as the corresponding line --> 
     <Rectangle 
      Height="10" 
      Width="10" 
      Fill="{Binding Path=LineStroke}" /> 
     <!-- The title of the corresponding line --> 
     <TextBlock 
      x:Name="Title" 
      Text="{Binding Path=DataSeries.Title}" /> 
     <!-- The actual value of the corresponding line on the current position--> 
     <TextBlock x:Name="Value"> 
      <TextBlock.Text> 
       <MultiBinding Converter="{StaticResource ChartSeriesBehaviourConverter}"> 
       <Binding ElementName=chart/> 
       <Binding/> 
       <MultiBinding> 
     </TextBlock> 
    </StackPanel> 
    </DataTemplate> 
</ListView.ItemTemplate> 
</ListView> 

를 추출 MultiBinding와 변환기를 사용 할 수있는 행동 chart 및 현재 계열 객체가 int를 전달했습니다. o var idx = chart.Series.IndexOf(s)과 같은 기능을 수행 할 수있는 변환기를 사용하면 동작의 해당 지점에 액세스 할 수 있습니다.

관련 문제