2017-11-26 8 views
0

내 ViewModel에는 PlanTable - PlanTable 목록이 있습니다. DayPlan은 Day 및 List ExercisesWithReps 문자열을 포함합니다. ExercisesWithReps 문자열 이름과 목록 담당자의 포함내부 목록 상자 항목을 선택할 때 외부 목록 항목을 선택하는 방법은 무엇입니까?

I (나는 이미 한 일을)이 사용 목록 상자를 모두 표시 할 수 있도록하려면 :. screenshot

때 ExerciseName 또는 어떤 사용자가 클릭 reps (number), 나는이 2 개 중 하나를 캡처 할 수 있기를 원합니다. 또한 하루 (예 : 사용자가 tesst 아래에서 12를 클릭하면 월요일에 나타나기를 원합니다.)에서 운동을 클릭하면 화요일, 화요일도 선택하도록). 그러나 나는 그것을 어떻게 이해할 수 없다 .. 여기에 순간에

내 코드입니다 : VIEW : 상기

 private List<DayPlan> planTable; 
    public List<DayPlan> PlanTable 
    { 
     get { return planTable; } 
     set 
     { 
      planTable = value; 
      RaisePropertyChanged(); 
     } 
    } 
public class DayPlan 
{ 
    public string Day { get; set; } 
    public List<Exercise> ExercisesWithReps { get; set; } 
    private Exercise selectedExerciseName; 
    public Exercise SelectedExerciseName 
    { 
     get { return selectedExerciseName; } 
     set 
     { 
      selectedExerciseName = value; 
      if (value != null) 
      { 
       TempExercise.Name = value.Name; 
      } 
     } 
    } 
} 
    public class Exercise 
{ 
    public string Name { get; set; } 
    public List<int> Reps { get; set; } 
    private int selectedReps; 
    public int SelectedReps 
    { 
     get { return selectedReps; } 
     set 
     { 
      selectedReps = value; 
      TempExercise.Reps = value; 
     } 
    } 
} 

: 여기

<ListBox Name="lbParent" Grid.Row="1" Grid.ColumnSpan="3" ItemsSource="{Binding PlanTable}" SelectedItem="{Binding SelectedListItem, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel HorizontalAlignment="Center"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="*"/> 
         <RowDefinition Height="*"/> 
         <RowDefinition Height="*"/> 
         <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
        <StackPanel> 
         <TextBlock Text="{Binding Day}" HorizontalAlignment="Center" Foreground="Black" Grid.Row="0" Margin="10"/> 
         <ListBox ItemsSource="{Binding ExercisesWithReps}" SelectedItem="{Binding SelectedExerciseName, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"> 
           <ListBox.ItemsPanel> 
           <ItemsPanelTemplate> 
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/> 
           </ItemsPanelTemplate> 
          </ListBox.ItemsPanel> 
          <ListBox.ItemTemplate> 
           <DataTemplate> 

            <StackPanel HorizontalAlignment="Center"> 
             <TextBlock Text="{Binding Path=Name}" HorizontalAlignment="Center"/> 
             <ListBox ItemsSource="{Binding Reps}" BorderBrush="Transparent" SelectedItem="{Binding SelectedReps, UpdateSourceTrigger=PropertyChanged}"> 
              <ListBox.ItemsPanel> 
               <ItemsPanelTemplate> 
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/> 
               </ItemsPanelTemplate> 
              </ListBox.ItemsPanel> 
              <ListBox.ItemTemplate> 
               <DataTemplate> 
                <TextBlock Text="{Binding }" HorizontalAlignment="Center"/> 
               </DataTemplate> 
              </ListBox.ItemTemplate> 
             </ListBox> 
            </StackPanel> 
           </DataTemplate> 
          </ListBox.ItemTemplate> 
         </ListBox> 
        </StackPanel> 



       </Grid> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 

뷰 모델 및 DayPlan입니다 모든 순간 (Day, ExerciseName, Reps)을 선택해야만 사용자의 선택을 포착 할 수 있습니다. 또한, 나는 이름과 담당자를 캡처하고있어 방법은 DayPlanSelectedExerciseName 속성이 설정 될 때마다

+0

TreeView를 사용하면 훨씬 쉬울 것이라고 생각합니다. – sTrenat

답변

0

SelectedListItem 속성을 설정 ... 내가이 뷰 모델에 캡처 할 만들 수 없습니다 ... 매우 불편 :

planTable = new List<DayPlan>() { ... }; 
foreach(var dayPlan in planTable) 
{ 
    dayPlan.PropertyChanged += (ss, ee) => 
    { 
     if(e.PropertyName == "SelectedExerciseName") 
     { 
      SelectedListItem = dayPlan; 
      RaisePropertyChanged("SelectedListItem"); 
     } 
    }; 
} 

이 은 SelectedExerciseName 속성이 새 값으로 설정되어있을 때 PropertyChanged 이벤트를 INotifyPropertyChanged 인터페이스를 구현하고 제기하는 DayPlan 클래스를 필요로한다. 또한 XAML의 바인딩에서 Mode=OneWayToSource을 제거해야합니다.

+0

어디에서 Foreach 루프를 사용할 수 있습니까? – Alex

+0

@Alex : 뷰 모델의 생성자 또는 PlanTable 속성을 초기화 할 때마다. – mm8

+0

목록 에는 PropertyChanged ...에 대한 정의가 없습니다. 그게 제가 가진 것입니다. – Alex